Skip to content
Snippets Groups Projects
Commit 11ce89c6 authored by Chad Leong's avatar Chad Leong :speech_balloon:
Browse files

Merge branch 'az/td-core-code-coverage' into 'master'

Improve Code Coverage % for Partition-core

See merge request !492
parents c14390d7 6fdb2885
No related branches found
No related tags found
1 merge request!492Improve Code Coverage % for Partition-core
Pipeline #229231 failed
variables:
CORE_BUILD_SUBDIR: partition-core
AWS_BUILD_SUBDIR: provider/partition-aws/build-aws
AWS_TEST_SUBDIR: testing/partition-test-aws
......
......@@ -178,6 +178,31 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<configuration>
<excludes>
<exclude>org/opengroup/osdu/partition/model/*</exclude>
<exclude>**/**Configuration*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package org.opengroup.osdu.partition.controller;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpStatus;
import static org.junit.Assert.assertEquals;
public class HealthCheckControllerTests {
private HealthCheckController sut;
@Before
public void setup() {
this.sut = new HealthCheckController();
}
@Test
public void should_returnHttp200_when_checkLiveness() {
assertEquals(HttpStatus.OK, this.sut.livenessCheck().getStatusCode());
}
}
package org.opengroup.osdu.partition.controller;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.info.VersionInfoBuilder;
import org.opengroup.osdu.core.common.model.info.VersionInfo;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class InfoControllerTest {
@InjectMocks
private InfoController sut;
@Mock
private VersionInfoBuilder versionInfoBuilder;
@Test
public void should_return200_getVersionInfo() throws IOException {
VersionInfo expectedVersionInfo = VersionInfo.builder()
.groupId("group")
.artifactId("artifact")
.version("0.1.0")
.buildTime("1000")
.branch("master")
.commitId("7777")
.commitMessage("Test commit")
.build();
when(versionInfoBuilder.buildVersionInfo()).thenReturn(expectedVersionInfo);
VersionInfo actualVersionInfo = this.sut.info();
assertEquals(expectedVersionInfo, actualVersionInfo);
}
}
package org.opengroup.osdu.partition.logging;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
public class AuditEventsTest {
@Test
public void shouldInitializeAuditEvents_whenUserIsValid() {
AuditEvents auditEvents = new AuditEvents("testUser");
assertNotNull(auditEvents);
}
@Test
public void shouldThrowIllegalArgumentException_whenAuditEvents_initializedWithEmptyUser() {
IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
() -> new AuditEvents(""));
assertEquals("User not provided for audit events.", illegalArgumentException.getMessage());
}
@Test
public void shouldThrowIllegalArgumentException_whenAuditEvents_initializedWithNullUser() {
IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
() -> new AuditEvents(null));
assertEquals("User not provided for audit events.", illegalArgumentException.getMessage());
}
}
......@@ -17,12 +17,6 @@
package org.opengroup.osdu.partition.logging;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -30,104 +24,125 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public class AuditLoggerTest {
@Mock
private JaxRsDpsLog log;
@Mock
private JaxRsDpsLog log;
@InjectMocks
private AuditLogger sut;
private List<String> resources;
@InjectMocks
private AuditLogger sut;
@Before
public void setup() {
resources = Collections.singletonList("resources");
}
private List<String> resources;
@Test
public void should_writeCreatePartitionSuccessEvent() {
this.sut.createPartitionSuccess(this.resources);
@Before
public void setup() {
resources = Collections.singletonList("resources");
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeCreatePartitionSuccessEvent() {
this.sut.createPartitionSuccess(this.resources);
@Test
public void should_writeCreatePartitionFailureEvent() {
this.sut.createPartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeCreatePartitionFailureEvent() {
this.sut.createPartitionFailure(this.resources);
@Test
public void should_writeReadPartitionSuccessEvent() {
this.sut.readPartitionSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadPartitionSuccessEvent() {
this.sut.readPartitionSuccess(this.resources);
@Test
public void should_writeReadPartitionFailureEvent() {
this.sut.readPartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadPartitionFailureEvent() {
this.sut.readPartitionFailure(this.resources);
@Test
public void should_writeDeletePartitionSuccessEvent() {
this.sut.deletePartitionSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeDeletePartitionSuccessEvent() {
this.sut.deletePartitionSuccess(this.resources);
@Test
public void should_writeDeletePartitionFailureEvent() {
this.sut.deletePartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeDeletePartitionFailureEvent() {
this.sut.deletePartitionFailure(this.resources);
@Test
public void should_writeReadServiceLivenessSuccessEvent() {
this.sut.readServiceLivenessSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadServiceLivenessSuccessEvent() {
this.sut.readServiceLivenessSuccess(this.resources);
@Test
public void should_writeReadServiceLivenessFailureEvent() {
this.sut.readServiceLivenessFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadServiceLivenessFailureEvent() {
this.sut.readServiceLivenessFailure(this.resources);
@Test
public void should_writeUpdatePartitionSecretSuccessEvent() {
this.sut.updatePartitionSecretSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeUpdatePartitionSecretSuccessEvent() {
this.sut.updatePartitionSecretSuccess(this.resources);
@Test
public void should_writeUpdatePartitionSecretFailureEvent() {
this.sut.updatePartitionSecretFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeUpdatePartitionSecretFailureEvent() {
this.sut.updatePartitionSecretFailure(this.resources);
@Test
public void should_writeReadListPartitionSuccessEvent() {
this.sut.readListPartitionSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadListPartitionSuccessEvent() {
this.sut.readListPartitionSuccess(this.resources);
@Test
public void should_writeReadListPartitionFailureEvent() {
this.sut.readListPartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadListPartitionFailureEvent() {
this.sut.readListPartitionFailure(this.resources);
@Test
public void should_initializeAuditEvents_onlyOnce() {
this.sut.readListPartitionFailure(new ArrayList<>());
Object events1 = ReflectionTestUtils.getField(this.sut, "events");
this.sut.readListPartitionFailure(this.resources);
Object events2 = ReflectionTestUtils.getField(this.sut, "events");
verify(this.log, times(1)).audit(any());
}
}
\ No newline at end of file
assertEquals(events1.hashCode(), events2.hashCode());
verify(this.log, times(2)).audit(any());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment