diff options
author | J Armstrong <joss.armstrong@ericsson.com> | 2018-06-18 12:41:39 +0100 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-06-20 13:43:10 +0000 |
commit | 1a2c68906675da494274d357c90ed48fc8050f67 (patch) | |
tree | 7ebd0f985f4d7d633bc46f32934fcdbef1c655c3 | |
parent | f3fe0cea8af6f8854452a3d92b09618403a30ed6 (diff) |
APPC-1009
Regex in appc-provider-model yang causes intermittent unit test failures
Change-Id: I5aefd746498737c10de4bd40a30d6aad2c629293
Signed-off-by: J Armstrong <joss.armstrong@ericsson.com>
Issue-ID: APPC-1009
-rw-r--r-- | appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java index eaa8c3216..9c74dc877 100644 --- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java +++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java @@ -131,33 +131,23 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.Co import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeaderBuilder; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBuilder; -import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.onap.appc.domainmodel.lcm.ResponseContext; import org.onap.appc.executor.objects.LCMCommandStatus; import org.onap.appc.provider.lcm.service.*; import org.onap.appc.provider.lcm.util.ValidationService; import org.onap.appc.requesthandler.objects.RequestHandlerOutput; -import org.osgi.framework.FrameworkUtil; import org.onap.appc.provider.Whitebox; +import java.text.DateFormat; +import java.text.SimpleDateFormat; -/* -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; -*/ - -import java.time.Clock; -import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; +import java.util.TimeZone; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -166,19 +156,12 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -/* -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.whenNew; -*/ /** * Integration Test class for AppcProviderLcm. */ @SuppressWarnings("deprecation") @RunWith(MockitoJUnitRunner.class) -// @PrepareForTest({FrameworkUtil.class, AppcProviderLcm.class, QueryService.class, VolumeService.class, -// QuiesceTrafficService.class, ValidationService.class}) - public class AppcProviderLcmTest extends AbstractDataBrokerTest { private Status successStatus = new StatusBuilder().setCode(400).setMessage("success").build(); private Status failStatus = new StatusBuilder().setCode(302) @@ -225,6 +208,13 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest { doReturn("success").when(successlcmStatus).getMessage(); } + @After + public void tearDown() throws Exception { + if (appcProviderLcm != null) { + appcProviderLcm.close(); + } + } + @Test public void testConstructor() throws Exception { Object executorService = Whitebox.getInternalState(appcProviderLcm, "executor"); @@ -1387,13 +1377,24 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest { //Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult()); } - @After - public void tearDown() throws Exception { - if (appcProviderLcm != null) { - appcProviderLcm.close(); - } - } + @Test + public void testTimestampFormatShort() throws Exception { + // Validation success + doReturn("Success").when(successlcmStatus).getMessage(); + doReturn(responseContext).when(requestHandlerOutput).getResponseContext(); + doReturn(requestHandlerOutput).when(appcProviderLcm).executeRequest(any()); + doReturn(null).when(validationService).validateInput(any(), any(), any()); + ConfigExportInput configExportInput = mock(ConfigExportInput.class); + long epochWithZeroFractionalSeconds = 1529495219000l; + doReturn(newCommonHeader("request-id-aduit", epochWithZeroFractionalSeconds)).when(configExportInput).getCommonHeader(); + doReturn(newActionIdentifier("vnf-id", "vnfc-id", "vserver-id")) + .when(configExportInput).getActionIdentifiers(); + + Future<RpcResult<ConfigExportOutput>> results = appcProviderLcm.configExport + (configExportInput); + Assert.assertEquals(302, (int)results.get().getResult().getStatus().getCode()); + } private ActionIdentifiers newActionIdentifier(String vnfId, String vnfcId, String vserverId) { ActionIdentifiersBuilder actionIdentifiersBuilder = new ActionIdentifiersBuilder(); @@ -1404,12 +1405,17 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest { } private CommonHeader newCommonHeader(String requestId) { + return newCommonHeader(requestId, System.currentTimeMillis()); + } + + private CommonHeader newCommonHeader(String requestId, long epoch) { CommonHeaderBuilder commonHeaderBuilder = new CommonHeaderBuilder(); commonHeaderBuilder.setRequestId(requestId); commonHeaderBuilder.setApiVer("2.0.0"); commonHeaderBuilder.setOriginatorId("originatortest"); - commonHeaderBuilder.setTimestamp(ZULU.getDefaultInstance(LocalDateTime.now(Clock.systemUTC()).toString() + - "Z")); + DateFormat ZULU_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"); + ZULU_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC")); + commonHeaderBuilder.setTimestamp(ZULU.getDefaultInstance(ZULU_FORMATTER.format(epoch))); return commonHeaderBuilder.build(); } } |