From ad07a8ba9780e2ffdb16c77d6a2970db42b1a957 Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Tue, 12 Sep 2017 20:37:34 -0400 Subject: Add unit test cases to increase coverage to 30% Remove classes that are already removed internally Use a unified AAISetup class that uses common configuration Issue-ID: AAI-213 Change-Id: If99b5230140ea300cd70eeaf9fd4064e4a07d99a Signed-off-by: Venkata Harish K Kajur --- .../src/test/java/org/openecomp/aai/AAISetup.java | 37 ++ .../interceptors/AAILogJAXRSInInterceptorTest.java | 39 ++ .../interceptors/PostAaiAjscInterceptorTest.java | 53 ++ .../interceptors/PreAaiAjscInterceptorTest.java | 41 ++ .../openecomp/aai/migration/VertexMergeTest.java | 64 +-- .../openecomp/aai/rest/BulkAddConsumerTest.java | 168 ++++++ .../aai/rest/BulkProcessConsumerTest.java | 54 ++ .../openecomp/aai/rest/ExampleConsumerTest.java | 131 +++++ .../openecomp/aai/rest/ExceptionHandlerTest.java | 138 +++++ .../openecomp/aai/rest/LegacyMoxyConsumerTest.java | 617 +++++++++++++++++++++ .../aai/rest/URLFromVertexIdConsumerTest.java | 179 ++++++ .../openecomp/aai/rest/VertexIdConsumerTest.java | 158 ++++++ .../aai/rest/retired/RetiredConsumerTest.java | 107 ++++ .../aai/rest/retired/V3ThroughV7ConsumerTest.java | 9 + .../openecomp/aai/rest/retired/V7V8ModelsTest.java | 9 + .../aai/rest/retired/V7V8NamedQueriesTest.java | 9 + .../rest/tools/ModelVersionTransformerTest.java | 116 ++++ .../openecomp/aai/rest/util/EchoResponseTest.java | 116 ++++ .../aai/rest/util/LogFormatToolsTest.java | 15 + .../aai/rest/util/ValidateEncodingTest.java | 9 +- .../org/openecomp/aai/schema/db/AuditOXMTest.java | 25 +- .../openecomp/aai/schema/db/ManageSchemaTest.java | 25 +- .../org/openecomp/aai/transforms/JoltTestUtil.java | 7 +- .../LowerHyphenToLowerCamelConverterTest.java | 73 +++ .../openecomp/aai/transforms/MapTraverserTest.java | 54 ++ .../aai/util/AAIApiServerURLBaseTest.java | 85 --- .../org/openecomp/aai/util/AAIApiVersionTest.java | 90 --- .../aai/util/AAIAppServletContextListenerTest.java | 25 +- .../org/openecomp/aai/util/AAICSVWriterTest.java | 19 +- .../aai/util/AAIConfigPasswordDecodingTest.java | 53 -- .../openecomp/aai/util/AAIRSyncUtilityTest.java | 21 +- .../aai/util/DataConversionHelperTest.java | 4 +- .../java/org/openecomp/aai/util/DbTestConfig.java | 12 +- .../org/openecomp/aai/util/DbTestFileWatcher.java | 4 +- .../openecomp/aai/util/DbTestProcessBuilder.java | 6 +- .../openecomp/aai/util/HbaseSaltPrefixerTest.java | 4 +- ...tyObfuscationConversionCommandLineUtilTest.java | 4 +- 37 files changed, 2208 insertions(+), 372 deletions(-) create mode 100644 aai-resources/src/test/java/org/openecomp/aai/AAISetup.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptorTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/interceptors/PostAaiAjscInterceptorTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/interceptors/PreAaiAjscInterceptorTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/BulkAddConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/BulkProcessConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/ExampleConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/ExceptionHandlerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/LegacyMoxyConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/URLFromVertexIdConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/VertexIdConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/retired/RetiredConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/retired/V3ThroughV7ConsumerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8ModelsTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8NamedQueriesTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/tools/ModelVersionTransformerTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/util/EchoResponseTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/rest/util/LogFormatToolsTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/transforms/LowerHyphenToLowerCamelConverterTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/transforms/MapTraverserTest.java delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/AAIApiServerURLBaseTest.java delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/AAIApiVersionTest.java delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/AAIConfigPasswordDecodingTest.java (limited to 'aai-resources/src/test/java') diff --git a/aai-resources/src/test/java/org/openecomp/aai/AAISetup.java b/aai-resources/src/test/java/org/openecomp/aai/AAISetup.java new file mode 100644 index 0000000..0f2480d --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/AAISetup.java @@ -0,0 +1,37 @@ +package org.openecomp.aai; + +import org.apache.commons.io.IOUtils; +import org.junit.BeforeClass; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.introspection.ModelInjestor; +import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper; +import org.openecomp.aai.util.AAIConstants; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertNotNull; + +public abstract class AAISetup { + + @BeforeClass + public static void setupBundleconfig() throws Exception { + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); + QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), + "src/test/resources/bundleconfig-local/etc/oxm/"); + } + + public String getPayload(String filename) throws IOException { + + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream(filename); + + String message = String.format("Unable to find the %s in src/test/resources", filename); + assertNotNull(message, inputStream); + + String resource = IOUtils.toString(inputStream); + return resource; + } +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptorTest.java b/aai-resources/src/test/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptorTest.java new file mode 100644 index 0000000..a61feba --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptorTest.java @@ -0,0 +1,39 @@ +package org.openecomp.aai.interceptors; + +import org.apache.cxf.message.Exchange; +import org.apache.cxf.message.ExchangeImpl; +import org.apache.cxf.message.Message; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.aai.AAISetup; + +import java.io.IOException; +import java.io.InputStream; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AAILogJAXRSInInterceptorTest extends AAISetup { + + private AAILogJAXRSInInterceptor aaiLogJAXRSInInterceptor; + + @Before + public void setup(){ + aaiLogJAXRSInInterceptor = new AAILogJAXRSInInterceptor(); + } + + @Test + public void testHandleMessageWhenNotCamelRequest() throws IOException { + + Message message = mock(Message.class); + Exchange exchange = new ExchangeImpl(); + InputStream is = getClass().getClassLoader().getResourceAsStream("logback.xml"); + + when(message.getExchange()).thenReturn(exchange); + when(message.getContent(InputStream.class)).thenReturn(is); + +// when(message.get(Message.QUERY_STRING)).thenReturn("/somestring"); + when(message.get("CamelHttpUrl")).thenReturn("/somestring"); + aaiLogJAXRSInInterceptor.handleMessage(message); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/interceptors/PostAaiAjscInterceptorTest.java b/aai-resources/src/test/java/org/openecomp/aai/interceptors/PostAaiAjscInterceptorTest.java new file mode 100644 index 0000000..dc6879d --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/interceptors/PostAaiAjscInterceptorTest.java @@ -0,0 +1,53 @@ +package org.openecomp.aai.interceptors; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.logging.LoggingContext; + +import javax.servlet.http.HttpServletRequest; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class PostAaiAjscInterceptorTest { + + private PostAaiAjscInterceptor postAaiAjscInterceptor; + + @Before + public void setup(){ + postAaiAjscInterceptor = new PostAaiAjscInterceptor(); + } + + @Test + public void getInstance() throws Exception { + PostAaiAjscInterceptor interceptor = PostAaiAjscInterceptor.getInstance(); + assertNotNull(interceptor); + } + + @Test + public void testAllowOrRejectIfSuccess() throws Exception { + + HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + + LoggingContext.put(LoggingContext.LoggingField.RESPONSE_CODE.toString(), "SUCCESS"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("/fadsjoifj")); + + boolean success = postAaiAjscInterceptor.allowOrReject(request, null, null); + + assertTrue("Expecting the post interceptor to return success regardless", success); + } + + @Test + public void testAllowOrRejectIfFailure() throws Exception { + + HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + + LoggingContext.put(LoggingContext.LoggingField.RESPONSE_CODE.toString(), "ERR."); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("/fadsjoifj")); + + boolean success = postAaiAjscInterceptor.allowOrReject(request, null, null); + + assertTrue("Expecting the post interceptor to return success regardless", success); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/interceptors/PreAaiAjscInterceptorTest.java b/aai-resources/src/test/java/org/openecomp/aai/interceptors/PreAaiAjscInterceptorTest.java new file mode 100644 index 0000000..5debe72 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/interceptors/PreAaiAjscInterceptorTest.java @@ -0,0 +1,41 @@ +package org.openecomp.aai.interceptors; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import javax.servlet.http.HttpServletRequest; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.anyString; + +public class PreAaiAjscInterceptorTest { + + private PreAaiAjscInterceptor preAaiAjscInterceptor; + + @Before + public void setup(){ + preAaiAjscInterceptor = new PreAaiAjscInterceptor(); + } + + @Test + public void getInstance() throws Exception { + PreAaiAjscInterceptor interceptor = PreAaiAjscInterceptor.getInstance(); + assertNotNull(interceptor); + } + + @Test + public void testAllowOrRejectIfSuccess() throws Exception { + + HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + + Mockito.when(request.getRequestURI()).thenReturn("/fadsjoifj"); + Mockito.when(request.getHeader(anyString())).thenReturn("JUNIT-Test"); + Mockito.when(request.getMethod()).thenReturn("GET"); + + boolean success = preAaiAjscInterceptor.allowOrReject(request, null, null); + + assertTrue("Expecting the post interceptor to return success regardless", success); + } + +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java b/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java index 5b71cf7..71e3827 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java @@ -20,26 +20,15 @@ package org.openecomp.aai.migration; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - +import com.thinkaurelius.titan.core.Cardinality; +import com.thinkaurelius.titan.core.TitanFactory; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.schema.TitanManagement; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; +import org.openecomp.aai.AAISetup; import org.openecomp.aai.db.props.AAIProperties; import org.openecomp.aai.dbmap.DBConnectionType; import org.openecomp.aai.introspection.Loader; @@ -51,36 +40,36 @@ import org.openecomp.aai.serialization.db.EdgeRules; import org.openecomp.aai.serialization.engines.QueryStyle; import org.openecomp.aai.serialization.engines.TitanDBEngine; import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; -import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper; -import org.openecomp.aai.util.AAIConstants; -import com.thinkaurelius.titan.core.Cardinality; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.schema.TitanManagement; +import java.io.UnsupportedEncodingException; +import java.util.*; + +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; @Ignore -public class VertexMergeTest { +public class VertexMergeTest extends AAISetup { private final static Version version = Version.v10; private final static ModelType introspectorFactoryType = ModelType.MOXY; private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; private final static DBConnectionType type = DBConnectionType.REALTIME; - private static Loader loader; - private static TransactionalGraphEngine dbEngine; - private static TitanGraph graph; - private static EdgeRules rules; - private static GraphTraversalSource g; - private static Graph tx; - @BeforeClass - public static void setUp() throws NoSuchFieldException, SecurityException, Exception { + private Loader loader; + private TransactionalGraphEngine dbEngine; + private TitanGraph graph; + private EdgeRules rules; + private GraphTraversalSource g; + private Graph tx; + + @Before + public void setUp() throws Exception { graph = TitanFactory.build().set("storage.backend","inmemory").open(); tx = graph.newTransaction(); g = tx.traversal(); - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); - QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/"); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); dbEngine = new TitanDBEngine( queryStyle, @@ -164,8 +153,9 @@ public class VertexMergeTest { VertexMerge merge = new VertexMerge.Builder(loader, spy, serializer).build(); merge.performMerge(pserverCanopi, pserverSkeleton, forceCopy); } - @AfterClass - public static void cleanUp() { + + @After + public void cleanUp() { tx.tx().rollback(); graph.close(); } diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/BulkAddConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/BulkAddConsumerTest.java new file mode 100644 index 0000000..2804566 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/BulkAddConsumerTest.java @@ -0,0 +1,168 @@ +package org.openecomp.aai.rest; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.introspection.ModelInjestor; +import org.openecomp.aai.introspection.Version; + +import javax.ws.rs.core.*; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public class BulkAddConsumerTest extends AAISetup { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + protected static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + protected BulkConsumer bulkConsumer; + + protected HttpHeaders httpHeaders; + + protected UriInfo uriInfo; + + protected MultivaluedMap headersMultiMap; + protected MultivaluedMap queryParameters; + + protected List aaiRequestContextList; + + protected List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(BulkAddConsumerTest.class.getName()); + + @BeforeClass + public static void setupRest(){ + AAIGraph.getInstance(); + ModelInjestor.getInstance(); + } + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + bulkConsumer = getConsumer(); + httpHeaders = Mockito.mock(HttpHeaders.class); + uriInfo = Mockito.mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void testBulkAdd() throws IOException { + + String uri = "/aai/v11/bulkadd"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + String payload = getBulkPayload("pserver-transactions"); + Response response = bulkConsumer.bulkAdd( + payload, + Version.getLatest().toString(), + httpHeaders, + uriInfo, + null + ); + + System.out.println("Code: " + response.getStatus() + "\tResponse: " + response.getEntity()); + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); + } + + @Test + public void testBulkAddThrowExceptionWhenPayloadContainsNoTransactions(){ + + String uri = "/aai/v11/bulkadd"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + String payload = "{\"transactions\":[]}"; + Response response = bulkConsumer.bulkAdd( + payload, + Version.getLatest().toString(), + httpHeaders, + uriInfo, + null + ); + + System.out.println("Code: " + response.getStatus() + "\tResponse: " + response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + } + + @Test + public void testBulkAddThrowExceptionWhenInvalidJson() throws IOException { + + String uri = "/aai/v11/bulkadd"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + String payload = "{"; + Response response = bulkConsumer.bulkAdd( + payload, + Version.getLatest().toString(), + httpHeaders, + uriInfo, + null + ); + + System.out.println("Code: " + response.getStatus() + "\tResponse: " + response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + + // TODO - Verify the result output and check if it contains an 400 in the list + } + + public String getBulkPayload(String bulkName) throws IOException { + return getPayload("payloads/bulk/" + bulkName + ".json"); + } + + public BulkConsumer getConsumer(){ + return new BulkAddConsumer(); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/BulkProcessConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/BulkProcessConsumerTest.java new file mode 100644 index 0000000..64639d4 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/BulkProcessConsumerTest.java @@ -0,0 +1,54 @@ +package org.openecomp.aai.rest; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.introspection.ModelInjestor; +import org.openecomp.aai.introspection.Version; + +import javax.ws.rs.core.*; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public class BulkProcessConsumerTest extends BulkAddConsumerTest { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(BulkProcessConsumerTest.class.getName()); + + @Test + public void testBulkAddCreatedWhenOneTransactionInPayloadContainsNotAllowedVerb() throws IOException { + + String uri = "/aai/v11/bulkadd"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + String payload = getBulkPayload("pserver-transactions-invalid"); + Response response = bulkConsumer.bulkAdd( + payload, + Version.getLatest().toString(), + httpHeaders, + uriInfo, + null + ); + + System.out.println("Code: " + response.getStatus() + "\tResponse: " + response.getEntity()); + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); + } + + @Override + public BulkConsumer getConsumer(){ + return new BulkProcessConsumer(); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/ExampleConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/ExampleConsumerTest.java new file mode 100644 index 0000000..28d5527 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/ExampleConsumerTest.java @@ -0,0 +1,131 @@ +package org.openecomp.aai.rest; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.introspection.ModelInjestor; +import org.openecomp.aai.introspection.Version; + +import javax.ws.rs.core.*; + +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public class ExampleConsumerTest extends AAISetup { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + private static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + private ExampleConsumer exampleConsumer; + + private HttpHeaders httpHeaders; + + private UriInfo uriInfo; + + private MultivaluedMap headersMultiMap; + private MultivaluedMap queryParameters; + + private List aaiRequestContextList; + + private List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(LegacyMoxyConsumerTest.class.getName()); + + @BeforeClass + public static void setupRest(){ + AAIGraph.getInstance(); + ModelInjestor.getInstance(); + } + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + exampleConsumer = new ExampleConsumer(); + httpHeaders = Mockito.mock(HttpHeaders.class); + uriInfo = Mockito.mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void testGetExampleRespondsWithOkStatusForValidObject(){ + + Response response = exampleConsumer.getExample( + Version.getLatest().toString(), + "pserver", + httpHeaders, + uriInfo, + null); + + assertNotNull("Response from the example consumer returned null", response); + + int code = Response.Status.OK.getStatusCode(); + + assertEquals(response.getStatus(), code); + } + + @Test + public void testGetExampleFailureForInvalidObject(){ + + when(uriInfo.getPath()).thenReturn("examples/fakeObject"); + when(uriInfo.getPath(false)).thenReturn("examples/fakeObject"); + + Response response = exampleConsumer.getExample( + Version.getLatest().toString(), + "testRandomCrazyObject", + httpHeaders, + uriInfo, + null); + + assertNotNull("Response from the example consumer returned null", response); + + int code = Response.Status.BAD_REQUEST.getStatusCode(); + + assertEquals(response.getStatus(), code); + } + +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/ExceptionHandlerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/ExceptionHandlerTest.java new file mode 100644 index 0000000..2c47a2e --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/ExceptionHandlerTest.java @@ -0,0 +1,138 @@ +package org.openecomp.aai.rest; + +import com.fasterxml.jackson.core.JsonLocation; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.sun.istack.SAXParseException2; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.aai.AAISetup; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ExceptionHandlerTest extends AAISetup { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + @Mock + private HttpHeaders httpHeaders; + + @Mock + private HttpServletRequest request; + + @InjectMocks + private ExceptionHandler handler = new ExceptionHandler(); + + @Before + public void setup(){ + MockitoAnnotations.initMocks(this); + + MultivaluedHashMap headersMultiMap = new MultivaluedHashMap<>(); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + List outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + } + + @Test + public void testConversionOfWebApplicationResponse() throws Exception { + + Exception exception = new WebApplicationException(); + Response response = handler.toResponse(exception); + + assertNotNull(response); + assertNull(response.getEntity()); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + } + + @Test + public void testConversionOfWebApplicationResponseWhenUmarshalExceptionResultBadRequest() throws Exception { + + SAXParseException2 mockSaxParseException = mock(SAXParseException2.class); + Exception exception = new WebApplicationException(mockSaxParseException); + Response response = handler.toResponse(exception); + + assertNotNull(response); + assertNotNull(response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + } + + @Test + public void testConversionWhenJsonParseExceptionResultBadRequest() throws Exception { + + JsonLocation jsonLocation = mock(JsonLocation.class); + Exception exception = new JsonParseException("", jsonLocation); + Response response = handler.toResponse(exception); + + assertNotNull(response); + assertNotNull(response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + } + + @Test + public void testConversionWhenJsonMappingExceptionResultBadRequest() throws Exception { + + JsonLocation jsonLocation = mock(JsonLocation.class); + Exception exception = new JsonMappingException("", jsonLocation); + Response response = handler.toResponse(exception); + + assertNotNull(response); + assertNotNull(response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + } + + @Test + public void testConversionWhenUnknownExceptionResultBadRequest() throws Exception { + + Exception exception = mock(Exception.class); + Response response = handler.toResponse(exception); + + when(request.getMethod()).thenReturn("GET"); + + assertNotNull(response); + assertNotNull(response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + + + } + + @Test + public void testConversionWhenUnknownExceptionResultBadRequestForXmlResponseType() throws Exception { + + List outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(MediaType.valueOf("application/xml")); + when(request.getMethod()).thenReturn("GET"); + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + + Exception exception = mock(Exception.class); + Response response = handler.toResponse(exception); + + assertNotNull(response); + assertNotNull(response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/LegacyMoxyConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/LegacyMoxyConsumerTest.java new file mode 100644 index 0000000..1620f3e --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/LegacyMoxyConsumerTest.java @@ -0,0 +1,617 @@ +package org.openecomp.aai.rest; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.introspection.ModelInjestor; +import org.openecomp.aai.introspection.Version; +import org.skyscreamer.jsonassert.JSONAssert; + +import javax.ws.rs.core.*; +import java.io.IOException; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public class LegacyMoxyConsumerTest extends AAISetup { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + private static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + private LegacyMoxyConsumer legacyMoxyConsumer; + + private HttpHeaders httpHeaders; + + private UriInfo uriInfo; + + private MultivaluedMap headersMultiMap; + private MultivaluedMap queryParameters; + + private List aaiRequestContextList; + + private List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(LegacyMoxyConsumerTest.class.getName()); + + @BeforeClass + public static void setupRest(){ + AAIGraph.getInstance(); + ModelInjestor.getInstance(); + } + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + legacyMoxyConsumer = new LegacyMoxyConsumer(); + httpHeaders = Mockito.mock(HttpHeaders.class); + uriInfo = Mockito.mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void testResponsePutGetDeleteOnResource() throws JSONException, IOException, AAIException { + + String uri = getUri(); + String payload = getResourcePayload(getObjectName()); + + assertNotNull("Introspector returned invalid string when marshalling the object", payload); + assertNotNull("Introspector failed to return a valid uri", uri); + + if(uri.length() != 0 && uri.charAt(0) == '/'){ + uri = uri.substring(1); + } + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + + response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); + + queryParameters.add("depth", "10000"); + + response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "10000", + "false", + httpHeaders, + uriInfo, + null + ); + + code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + String pserverEntity = response.getEntity().toString(); + JSONObject pserverJsonbject = new JSONObject(pserverEntity); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + + JSONAssert.assertEquals(payload, pserverEntity, false); + + String resourceVersion = pserverJsonbject.getString("resource-version"); + + queryParameters.add("resource-version", resourceVersion); + + response = legacyMoxyConsumer.delete( + "v11", + uri, + httpHeaders, + uriInfo, + "", + null + ); + + code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); + + response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + } + + @Test + public void testPutPserverAndCloudRegionRelationship() throws IOException, JSONException { + + String pserverData = getRelationshipPayload("pserver"); + String complexData = getRelationshipPayload("complex"); + + String hostname = "590a8943-1200-43b3-825b-75dde6b8f44a"; + String physicalLocationId ="e13d4587-19ad-4bf5-80f5-c021efb5b61c"; + + String pserverUri = String.format("cloud-infrastructure/pservers/pserver/%s", hostname); + String cloudRegionUri = String.format("cloud-infrastructure/complexes/complex/%s", physicalLocationId); + + doSetupResource(pserverUri, pserverData); + doSetupResource(cloudRegionUri, complexData); + + String cloudToPserverRelationshipData = getRelationshipPayload("pserver-complex-relationship"); + String cloudToPserverRelationshipUri = String.format( + "cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship", hostname); + + Response response = legacyMoxyConsumer.updateRelationship( + cloudToPserverRelationshipData, + Version.getLatest().toString(), + cloudToPserverRelationshipUri, + httpHeaders, + uriInfo, + null + ); + + assertNotNull("Response from the legacy moxy consumer returned null", response); + int code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + assertEquals("Expected to return status created from the response", + Response.Status.OK.getStatusCode(), response.getStatus()); + logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); + + // TODO - Need to actually verify the relationship between pserver and cloud-region + + response = legacyMoxyConsumer.deleteRelationship( + cloudToPserverRelationshipData, + Version.getLatest().toString(), + cloudToPserverRelationshipUri, + httpHeaders, + uriInfo, + null + ); + + code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); + } + + @Test + public void testPutPassWithEmptyData() throws JSONException { + + String payload = "{}"; + String pserverUri = String.format("cloud-infrastructure/pservers/pserver/%s", UUID.randomUUID().toString()); + + doSetupResource(pserverUri, payload); + + payload = ""; + pserverUri = String.format("cloud-infrastructure/pservers/pserver/%s", UUID.randomUUID().toString()); + doSetupResource(pserverUri, payload); + } + + @Test + public void testFailureWithInvalidUri() throws JSONException { + + String payload = "{}"; + String uri = "fake-infrastructure/pservers/pserver/fajsidj"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), code); + } + + @Test + public void testInvalidUriThrowRandomException() throws JSONException { + + String payload = "{}"; + String uri = "fake-infrastructure/pservers/pserver/fajsidj"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenThrow(new IllegalArgumentException()); + + Response response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + assertNotNull("Response from the legacy moxy consumer returned null", response); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + + response = legacyMoxyConsumer.updateRelationship( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + code = response.getStatus(); + assertNotNull("Response from the legacy moxy consumer returned null", response); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + + response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertNotNull("Response from the legacy moxy consumer returned null", response); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + + response = legacyMoxyConsumer.delete( + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + "", + null + ); + + code = response.getStatus(); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + + response = legacyMoxyConsumer.deleteRelationship( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + code = response.getStatus(); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + } + + @Test + public void testInvalidUriContainingRelatedToShouldThrowAAIException() throws JSONException { + + String payload = "{}"; + String uri = "cloud-infrastructure/related-to/fsdf"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + + response = legacyMoxyConsumer.updateRelationship( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + code = response.getStatus(); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + + response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertNotNull("Response from the legacy moxy consumer returned null", response); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + + queryParameters.add("resource-version", "3434394839483"); + response = legacyMoxyConsumer.delete( + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + "", + null + ); + + code = response.getStatus(); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), code); + + response = legacyMoxyConsumer.deleteRelationship( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + code = response.getStatus(); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), code); + } + + @Test + @Ignore("Unable to test this method due to WRITE_BIGDECIMAL_AS_PLAIN error") + public void testPatchWithValidData() throws IOException { + + String payload = getResourcePayload("pserver-patch-test"); + String uri = getUri("pserver-patch-test"); + + if(uri.length() != 0 && uri.charAt(0) == '/'){ + uri = uri.substring(1); + } + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + + response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); + + String patchData = "{\"in-maint\": false}"; + + headersMultiMap.add("Content-Type", "application/json"); + + outputMediaTypes.remove(APPLICATION_JSON); + outputMediaTypes.add(MediaType.valueOf("application/merge-patch+json")); + + response = legacyMoxyConsumer.patch( + patchData, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + code = response.getStatus(); + assertNotNull("Response from the patch returned null", response); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + assertEquals(Response.Status.OK.getStatusCode(), code); + + } + + protected void doSetupResource(String uri, String payload) throws JSONException { + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertNotNull("Response from the legacy moxy consumer returned null", response); + assertEquals("Expected to not have the data already in memory", + Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + + response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + assertNotNull("Response from the legacy moxy consumer returned null", response); + int code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + assertEquals("Expected to return status created from the response", + Response.Status.CREATED.getStatusCode(), response.getStatus()); + + queryParameters.add("depth", "10000"); + response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertNotNull("Response from the legacy moxy consumer returned null", response); + assertEquals("Expected to return the pserver data that was just put in memory", + Response.Status.OK.getStatusCode(), response.getStatus()); + + if("".equalsIgnoreCase(payload)){ + payload = "{}"; + } + + JSONAssert.assertEquals(payload, response.getEntity().toString(), false); + } + + @Test + public void testDeleteRelationshipThrowsException(){ + + String payload = ""; + String hostname = "testData"; + String uri = String.format("cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship", hostname); + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.deleteRelationship( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), code); + } + + // TODO - Change this to be abstract and inheritable + public String getObjectName(){ + return "pserver"; + } + + public String getResourcePayload(String resourceName) throws IOException { + return getPayload("payloads/resource/" + resourceName + ".json"); + } + + public String getRelationshipPayload(String relationshipName) throws IOException { + return getPayload("payloads/relationship/" + relationshipName + ".json"); + } + + public String getUri(String hostname){ + return String.format("cloud-infrastructure/pservers/pserver/%s", hostname); + } + + public String getUri(){ + return getUri("pserver-hostname-test"); + } +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/URLFromVertexIdConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/URLFromVertexIdConsumerTest.java new file mode 100644 index 0000000..5ba9ea6 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/URLFromVertexIdConsumerTest.java @@ -0,0 +1,179 @@ +package org.openecomp.aai.rest; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.json.JSONException; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.introspection.ModelInjestor; +import org.openecomp.aai.introspection.Version; + +import javax.ws.rs.core.*; +import java.io.IOException; +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public class URLFromVertexIdConsumerTest extends AAISetup { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + private static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + private URLFromVertexIdConsumer urlFromVertexIdConsumer; + private LegacyMoxyConsumer legacyMoxyConsumer; + + private HttpHeaders httpHeaders; + + private UriInfo uriInfo; + + private MultivaluedMap headersMultiMap; + private MultivaluedMap queryParameters; + + private List aaiRequestContextList; + + private List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(LegacyMoxyConsumerTest.class.getName()); + + @BeforeClass + public static void setupRest(){ + AAIGraph.getInstance(); + ModelInjestor.getInstance(); + } + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + urlFromVertexIdConsumer = new URLFromVertexIdConsumer(); + legacyMoxyConsumer = new LegacyMoxyConsumer(); + + httpHeaders = Mockito.mock(HttpHeaders.class); + uriInfo = Mockito.mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void testResponsePutGetDeleteOnResource() throws JSONException, IOException, AAIException { + + String uri = "cloud-infrastructure/pservers/pserver/" + UUID.randomUUID().toString(); + String payload = "{}"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + + response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); + + MultivaluedMap responseHeaders = response.getMetadata(); + + assertNotNull("Unable to retrieve the response headers from response object", responseHeaders); + assertTrue("Response doesn't contain the key vertexId", responseHeaders.containsKey("vertex-id")); + + String vertexId = responseHeaders.get("vertex-id").get(0).toString(); + + response = urlFromVertexIdConsumer.generateUrlFromVertexId( + "", + Version.getLatest().toString(), + Long.valueOf(vertexId).longValue(), + httpHeaders, + uriInfo, + null + ); + + assertNotNull(response); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + } + + @Test + public void testObjectNotFoundInDBReturnsNotFoundStatus() throws JSONException, IOException, AAIException { + + String uri = "cloud-infrastructure/pservers/pserver/testRandom"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + String vertexId = "384584"; + + Response response = urlFromVertexIdConsumer.generateUrlFromVertexId( + "", + Version.getLatest().toString(), + Long.valueOf(vertexId).longValue(), + httpHeaders, + uriInfo, + null + ); + + assertNotNull("Check if the response is not null", response); + + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/VertexIdConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/VertexIdConsumerTest.java new file mode 100644 index 0000000..12e2411 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/VertexIdConsumerTest.java @@ -0,0 +1,158 @@ +package org.openecomp.aai.rest; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.json.JSONException; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.introspection.ModelInjestor; +import org.openecomp.aai.introspection.Version; + +import javax.ws.rs.core.*; +import java.io.IOException; +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public class VertexIdConsumerTest extends AAISetup { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + private static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + private VertexIdConsumer vertexIdConsumer; + private LegacyMoxyConsumer legacyMoxyConsumer; + + private HttpHeaders httpHeaders; + + private UriInfo uriInfo; + + private MultivaluedMap headersMultiMap; + private MultivaluedMap queryParameters; + + private List aaiRequestContextList; + + private List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(LegacyMoxyConsumerTest.class.getName()); + + @BeforeClass + public static void setupRest(){ + AAIGraph.getInstance(); + ModelInjestor.getInstance(); + } + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + vertexIdConsumer = new VertexIdConsumer(); + legacyMoxyConsumer = new LegacyMoxyConsumer(); + + httpHeaders = Mockito.mock(HttpHeaders.class); + uriInfo = Mockito.mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void testResponsePutGetDeleteOnResource() throws JSONException, IOException, AAIException { + + String uri = "cloud-infrastructure/pservers/pserver/" + UUID.randomUUID().toString(); + String payload = "{}"; + + when(uriInfo.getPath()).thenReturn(uri); + when(uriInfo.getPath(false)).thenReturn(uri); + + Response response = legacyMoxyConsumer.getLegacy( + "", + Version.getLatest().toString(), + uri, + "all", + "false", + httpHeaders, + uriInfo, + null + ); + + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + + response = legacyMoxyConsumer.update( + payload, + Version.getLatest().toString(), + uri, + httpHeaders, + uriInfo, + null + ); + + int code = response.getStatus(); + if(!VALID_HTTP_STATUS_CODES.contains(code)){ + System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity()); + } + + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); + + MultivaluedMap responseHeaders = response.getMetadata(); + + assertNotNull("Unable to retrieve the response headers from response object", responseHeaders); + assertTrue("Response doesn't contain the key vertexId", responseHeaders.containsKey("vertex-id")); + + String vertexId = responseHeaders.get("vertex-id").get(0).toString(); + + response = vertexIdConsumer.getByVertexId( + "", + Version.getLatest().toString(), + Long.valueOf(vertexId).longValue(), + "10000", + httpHeaders, + uriInfo, + null + ); + + assertNotNull(response); + String pserverObject = response.getEntity().toString(); + + System.out.println(pserverObject); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/retired/RetiredConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/RetiredConsumerTest.java new file mode 100644 index 0000000..1f204f5 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/RetiredConsumerTest.java @@ -0,0 +1,107 @@ +package org.openecomp.aai.rest.retired; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.introspection.Version; + +import javax.ws.rs.core.*; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public abstract class RetiredConsumerTest { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + private static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + protected RetiredConsumer retiredConsumer; + protected HttpHeaders httpHeaders; + protected UriInfo uriInfo; + + private MultivaluedMap headersMultiMap; + private MultivaluedMap queryParameters; + + private List aaiRequestContextList; + + private List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(RetiredConsumer.class.getName()); + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + retiredConsumer = getRetiredConsumer(); + httpHeaders = Mockito.mock(HttpHeaders.class); + uriInfo = Mockito.mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void testRetiredForAllEndPoints(){ + when(uriInfo.getPath()).thenReturn("/aai/v3/cloud-infrastructure/pservers/pserver/test-pserver1"); + + Response response = retiredConsumer.createMessageGet(Version.getLatest().toString(), httpHeaders, uriInfo, null); + assertNotNull(response); + assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); + + response = retiredConsumer.createMessagePost(Version.getLatest().toString(), httpHeaders, uriInfo, null); + assertNotNull(response); + assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); + + response = retiredConsumer.createMessagePatch(Version.getLatest().toString(), httpHeaders, uriInfo, null); + assertNotNull(response); + assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); + + response = retiredConsumer.createMessagePut(Version.getLatest().toString(), httpHeaders, uriInfo, null); + assertNotNull(response); + assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); + + response = retiredConsumer.createMessageDelete(Version.getLatest().toString(), httpHeaders, uriInfo, null); + assertNotNull(response); + assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); + } + + public abstract RetiredConsumer getRetiredConsumer(); +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V3ThroughV7ConsumerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V3ThroughV7ConsumerTest.java new file mode 100644 index 0000000..8dc1c10 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V3ThroughV7ConsumerTest.java @@ -0,0 +1,9 @@ +package org.openecomp.aai.rest.retired; + +public class V3ThroughV7ConsumerTest extends RetiredConsumerTest { + + @Override + public RetiredConsumer getRetiredConsumer() { + return new V3ThroughV7Consumer(); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8ModelsTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8ModelsTest.java new file mode 100644 index 0000000..b6c340e --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8ModelsTest.java @@ -0,0 +1,9 @@ +package org.openecomp.aai.rest.retired; + +public class V7V8ModelsTest extends RetiredConsumerTest { + + @Override + public RetiredConsumer getRetiredConsumer() { + return new V7V8Models(); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8NamedQueriesTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8NamedQueriesTest.java new file mode 100644 index 0000000..db4d35d --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/retired/V7V8NamedQueriesTest.java @@ -0,0 +1,9 @@ +package org.openecomp.aai.rest.retired; + +public class V7V8NamedQueriesTest extends RetiredConsumerTest { + + @Override + public RetiredConsumer getRetiredConsumer() { + return new V7V8NamedQueries(); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/tools/ModelVersionTransformerTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/tools/ModelVersionTransformerTest.java new file mode 100644 index 0000000..75d25df --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/tools/ModelVersionTransformerTest.java @@ -0,0 +1,116 @@ +package org.openecomp.aai.rest.tools; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.introspection.ModelInjestor; +import org.skyscreamer.jsonassert.JSONAssert; + +import javax.ws.rs.core.*; +import java.util.*; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + +public class ModelVersionTransformerTest extends AAISetup { + + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + private static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + private ModelVersionTransformer modelVersionTransformer; + + private HttpHeaders httpHeaders; + + private UriInfo uriInfo; + + private MultivaluedMap headersMultiMap; + private MultivaluedMap queryParameters; + + private List aaiRequestContextList; + + private List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ModelVersionTransformerTest.class.getName()); + + @BeforeClass + public static void setupRest(){ + AAIGraph.getInstance(); + ModelInjestor.getInstance(); + } + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + modelVersionTransformer = new ModelVersionTransformer(); + httpHeaders = Mockito.mock(HttpHeaders.class); + uriInfo = Mockito.mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Content-Type", "application/xml"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void modelTransform() throws Exception { + + String modelXmlPayload = getPayload("payloads/modeltransforms/model.xml"); + String modelJsonPayload = getPayload("payloads/modeltransforms/model.json"); + + String uri = "modeltransform"; + + when(uriInfo.getPath()).thenReturn(uri); + // Comment the following line for the null pointer exception + when(uriInfo.getPath(false)).thenReturn(uri); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(MediaType.valueOf("application/xml")); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + when(httpHeaders.getMediaType()).thenReturn(MediaType.valueOf("application/xml")); + + Response response = modelVersionTransformer.modelTransform(modelXmlPayload,uri, httpHeaders, uriInfo, null); + + assertNotNull(response); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/util/EchoResponseTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/util/EchoResponseTest.java new file mode 100644 index 0000000..c4d435a --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/util/EchoResponseTest.java @@ -0,0 +1,116 @@ +package org.openecomp.aai.rest.util; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.AAISetup; + +import javax.ws.rs.core.*; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class EchoResponseTest extends AAISetup { + + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); + + private static final Set VALID_HTTP_STATUS_CODES = new HashSet<>(); + + static { + VALID_HTTP_STATUS_CODES.add(200); + VALID_HTTP_STATUS_CODES.add(201); + VALID_HTTP_STATUS_CODES.add(204); + } + + private EchoResponse echoResponse; + + private HttpHeaders httpHeaders; + + private UriInfo uriInfo; + + private MultivaluedMap headersMultiMap; + private MultivaluedMap queryParameters; + + private List aaiRequestContextList; + + private List outputMediaTypes; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(EchoResponseTest.class.getName()); + + @Before + public void setup(){ + logger.info("Starting the setup for the integration tests of Rest Endpoints"); + + echoResponse = new EchoResponse(); + httpHeaders = mock(HttpHeaders.class); + uriInfo = mock(UriInfo.class); + + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + + headersMultiMap.add("X-FromAppId", "JUNIT"); + headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); + headersMultiMap.add("Real-Time", "true"); + headersMultiMap.add("Accept", "application/json"); + headersMultiMap.add("aai-request-context", ""); + + outputMediaTypes = new ArrayList<>(); + outputMediaTypes.add(APPLICATION_JSON); + + aaiRequestContextList = new ArrayList<>(); + aaiRequestContextList.add(""); + + when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); + when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); + when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Arrays.asList("JUNIT")); + when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Arrays.asList("JUNIT")); + + when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + + + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); + + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable + Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + + when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); + } + + @Test + public void testEchoResultWhenValidHeaders() throws Exception { + + Response response = echoResponse.echoResult(httpHeaders, null, ""); + + assertNotNull(response); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + } + + @Test + public void testEchoResultWhenInValidHeadersThrowsBadRequest() throws Exception { + + httpHeaders = mock(HttpHeaders.class); + Response response = echoResponse.echoResult(httpHeaders, null, ""); + + assertNotNull(response); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + } + + @Test + public void testEchoResultWhenValidHeadersButMediaTypeWrong() throws Exception { + + when(httpHeaders.getAcceptableMediaTypes()).thenThrow(new IllegalStateException()) + .thenReturn(outputMediaTypes); + + Response response = echoResponse.echoResult(httpHeaders, null, ""); + + assertNotNull(response); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/util/LogFormatToolsTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/util/LogFormatToolsTest.java new file mode 100644 index 0000000..55d8ce3 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/util/LogFormatToolsTest.java @@ -0,0 +1,15 @@ +package org.openecomp.aai.rest.util; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class LogFormatToolsTest { + + @Test + public void testLogFormatTools(){ + + String dateTime = new LogFormatTools().getCurrentDateTime(); + assertNotNull(dateTime); + } +} \ No newline at end of file diff --git a/aai-resources/src/test/java/org/openecomp/aai/rest/util/ValidateEncodingTest.java b/aai-resources/src/test/java/org/openecomp/aai/rest/util/ValidateEncodingTest.java index 8c6450d..220d7d3 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/rest/util/ValidateEncodingTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/rest/util/ValidateEncodingTest.java @@ -20,16 +20,15 @@ package org.openecomp.aai.rest.util; -import static org.junit.Assert.*; - -import java.io.UnsupportedEncodingException; +import org.junit.Test; +import org.mockito.Mockito; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; +import java.io.UnsupportedEncodingException; -import org.junit.Test; -import org.mockito.Mockito; +import static org.junit.Assert.assertEquals; public class ValidateEncodingTest { diff --git a/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java b/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java index 8e9e322..f76c151 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java @@ -20,36 +20,25 @@ package org.openecomp.aai.schema.db; -import java.io.IOException; - +import com.thinkaurelius.titan.core.TitanFactory; +import com.thinkaurelius.titan.core.TitanGraph; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; -import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; - +import org.openecomp.aai.AAISetup; import org.openecomp.aai.db.schema.AuditDoc; import org.openecomp.aai.db.schema.AuditOXM; import org.openecomp.aai.db.schema.Auditor; import org.openecomp.aai.db.schema.AuditorFactory; import org.openecomp.aai.introspection.Version; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; + +import java.io.IOException; @Ignore("not ready for testing") -public class AuditOXMTest { - - /** - * Before. - */ - @BeforeClass - public static void before() { - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); - - } - +public class AuditOXMTest extends AAISetup { + /** * Gets the graph audit. diff --git a/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java b/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java index 9dade87..c11358f 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java @@ -20,34 +20,27 @@ package org.openecomp.aai.schema.db; -import java.io.IOException; -import java.util.Set; - +import com.thinkaurelius.titan.core.TitanFactory; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.schema.TitanManagement; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; - +import org.openecomp.aai.AAISetup; import org.openecomp.aai.db.schema.DBIndex; import org.openecomp.aai.db.schema.ManageTitanSchema; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.schema.TitanManagement; + +import java.io.IOException; +import java.util.Set; @Ignore("not ready yet") -public class ManageSchemaTest { +public class ManageSchemaTest extends AAISetup { private TitanGraph graph = null; - @BeforeClass - public static void before() { - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); - - } - + @Before public void beforeTest() { //graph = TitanFactory.open("src/test/resources/inmemory_titan.properties"); diff --git a/aai-resources/src/test/java/org/openecomp/aai/transforms/JoltTestUtil.java b/aai-resources/src/test/java/org/openecomp/aai/transforms/JoltTestUtil.java index 7df2790..d691545 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/transforms/JoltTestUtil.java +++ b/aai-resources/src/test/java/org/openecomp/aai/transforms/JoltTestUtil.java @@ -21,13 +21,12 @@ package org.openecomp.aai.transforms; -import java.io.IOException; - -import org.junit.Assert; - import com.bazaarvoice.jolt.ArrayOrderObliviousDiffy; import com.bazaarvoice.jolt.Diffy; import com.bazaarvoice.jolt.JsonUtils; +import org.junit.Assert; + +import java.io.IOException; public class JoltTestUtil { diff --git a/aai-resources/src/test/java/org/openecomp/aai/transforms/LowerHyphenToLowerCamelConverterTest.java b/aai-resources/src/test/java/org/openecomp/aai/transforms/LowerHyphenToLowerCamelConverterTest.java new file mode 100644 index 0000000..4f408b0 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/transforms/LowerHyphenToLowerCamelConverterTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.aai.transforms; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class LowerHyphenToLowerCamelConverterTest { + + private Converter converter = new LowerHyphenToLowerCamelConverter(); + + private String input; + private String expected; + + public LowerHyphenToLowerCamelConverterTest(String input, String expected){ + this.input = input; + this.expected = expected; + } + + /** + * Data Provider for the Lower Hyphen to Camel Converter Tests + * Make sure the capitalization is not lost during the conversion + * @return + */ + @Parameters + public static Collection data(){ + + return Arrays.asList(new Object[][]{ + {null, null}, + {"test-name", "testName"}, + {"test---name", "testName"}, // Case multiple + {"testName", "testName"}, // Case where upper case word shouldn't be lowercased + {"test-name-cool", "testNameCool"}, + {"test-name-Cool", "testNameCool"}, + {"test-name-Cool-Name-wow----Rest", "testNameCoolNameWowRest"}, + {"test-name#fast#", "testName#fast#"}, + {"test-name---", "testName"}, + {"----test-name", "TestName"}, + }); + } + + @Test + public void testIfInputSuccessfullyModified(){ + String actual = converter.convert(input); + assertEquals(expected, actual); + } +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/transforms/MapTraverserTest.java b/aai-resources/src/test/java/org/openecomp/aai/transforms/MapTraverserTest.java new file mode 100644 index 0000000..78fc88d --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/transforms/MapTraverserTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.aai.transforms; + +import com.bazaarvoice.jolt.JsonUtils; +import org.junit.Test; + +import java.io.IOException; +import java.util.Map; + +public class MapTraverserTest { + + private final String testResources = "src/test/resources/maputils/testcases/"; + + private String[] testCases = { "TestCase1.json", "TestCase2.json" }; + private MapTraverser traverser = new MapTraverser(new LowerCamelToLowerHyphenConverter()); + + @Test(expected = NullPointerException.class) + public void testIfMapIsNullThrowNullPointerException(){ + Map map = null; + traverser.convertKeys(map); + } + + @Test + public void runTestCases() throws IOException { + + for(String testCase : testCases){ + Map values = JsonUtils.filepathToMap(testResources + testCase); + + Object input = values.get("input"); + Object actual = traverser.convertKeys((Map)input); + Object output = values.get("output"); + JoltTestUtil.runArrayOrderObliviousDiffy( "failed case " + testCase, output, actual ); + } + } +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAIApiServerURLBaseTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAIApiServerURLBaseTest.java deleted file mode 100644 index 394f636..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/util/AAIApiServerURLBaseTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.openecomp.aai - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.aai.util; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.message.Message; -import org.apache.cxf.message.MessageImpl; -import org.apache.cxf.phase.PhaseInterceptorChain; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import static org.mockito.Mockito.*; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.agent.PowerMockAgent; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.rule.PowerMockRule; - -@PrepareForTest({PhaseInterceptorChain.class, AAIConfig.class}) - -public class AAIApiServerURLBaseTest { - @Rule - public PowerMockRule rule = new PowerMockRule(); - - static { - PowerMockAgent.initializeIfNeeded(); - } - - /** - * Test get hostname. - * - * @throws Exception the exception - */ - @Test - public void testGetHostname() throws Exception { - PowerMockito.mockStatic(PhaseInterceptorChain.class); - Map > hm = new HashMap>(); - List host = new ArrayList(); - host.add("my-localhost"); - hm.put("host", host); - - Message outMessage = new MessageImpl(); - outMessage.put(Message.PROTOCOL_HEADERS, hm); - - when(PhaseInterceptorChain.getCurrentMessage()).thenReturn(outMessage); - assertEquals("https://my-localhost/aai/", AAIApiServerURLBase.get()); - } - - /** - * Test get with null hostname. - * - * @throws Exception the exception - */ - @Test - public void testGetWithNullHostname() throws Exception { - PowerMockito.mockStatic(AAIConfig.class); - String defaultHostname = "default-name"; - when(AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE)).thenReturn(defaultHostname); - assertEquals(defaultHostname, AAIApiServerURLBase.get()); - } -} diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAIApiVersionTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAIApiVersionTest.java deleted file mode 100644 index f82fc5d..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/util/AAIApiVersionTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.openecomp.aai - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.aai.util; - -import static org.junit.Assert.*; - -import org.apache.cxf.message.Message; -import org.apache.cxf.message.MessageImpl; -import org.apache.cxf.phase.PhaseInterceptorChain; -import org.junit.Rule; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; -import static org.mockito.Mockito.*; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.agent.PowerMockAgent; -import org.powermock.modules.junit4.rule.PowerMockRule; - -@PrepareForTest({PhaseInterceptorChain.class, AAIConfig.class}) - -public class AAIApiVersionTest { - @Rule - public PowerMockRule rule = new PowerMockRule(); - - static { PowerMockAgent.initializeIfNeeded();} - - /** - * Test get version. - * - * @throws Exception the exception - */ - @Test - public void testGetVersion() throws Exception { - PowerMockito.mockStatic(PhaseInterceptorChain.class); - Message outMessage = new MessageImpl(); - String msg = "/v2/"; - outMessage.put(Message.REQUEST_URI, msg); - when(PhaseInterceptorChain.getCurrentMessage()).thenReturn(outMessage); - assertEquals("v2", AAIApiVersion.get()); - } - - /** - * Test get with null version. - * - * @throws Exception the exception - */ - @Test - public void testGetWithNullVersion() throws Exception { - PowerMockito.mockStatic(AAIConfig.class); - String defaultURI = "default-v2"; - when(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP, AAIConstants.AAI_DEFAULT_API_VERSION)).thenReturn(defaultURI); - assertEquals(defaultURI, AAIApiVersion.get()); - } - - /** - * Test incorrect version pattern. - * - * @throws Exception the exception - */ - @Test - public void testIncorrectVersionPattern() throws Exception { - PowerMockito.mockStatic(PhaseInterceptorChain.class); - PowerMockito.mockStatic(AAIConfig.class); - Message outMessage = new MessageImpl(); - String msg = "2.0.1"; - String defaultURI = "default-v2"; - outMessage.put(Message.REQUEST_URI, msg); - when(PhaseInterceptorChain.getCurrentMessage()).thenReturn(outMessage); - when(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP, AAIConstants.AAI_DEFAULT_API_VERSION)).thenReturn(defaultURI); - assertEquals(defaultURI, AAIApiVersion.get()); - } - -} diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAIAppServletContextListenerTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAIAppServletContextListenerTest.java index deafd5b..a148bea 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/AAIAppServletContextListenerTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/AAIAppServletContextListenerTest.java @@ -20,31 +20,28 @@ package org.openecomp.aai.util; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.ServletContextEvent; - +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.PatternLayout; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.logging.ErrorLogHelper; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.agent.PowerMockAgent; import org.powermock.modules.junit4.rule.PowerMockRule; import org.slf4j.LoggerFactory; -import org.openecomp.aai.dbmap.AAIGraph; -import org.openecomp.aai.logging.ErrorLogHelper; +import javax.servlet.ServletContextEvent; +import java.util.ArrayList; +import java.util.List; -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.PatternLayout; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.AppenderBase; +import static org.junit.Assert.assertTrue; @PrepareForTest({AAIGraph.class, AAIConfig.class, ErrorLogHelper.class}) public class AAIAppServletContextListenerTest { diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAICSVWriterTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAICSVWriterTest.java index c3e525c..4f2dfd1 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/AAICSVWriterTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/AAICSVWriterTest.java @@ -20,18 +20,6 @@ package org.openecomp.aai.util; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Writer; -import java.nio.file.Files; -import java.nio.file.Paths; - import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -39,6 +27,13 @@ import org.junit.Test; import org.powermock.modules.agent.PowerMockAgent; import org.powermock.modules.junit4.rule.PowerMockRule; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + public class AAICSVWriterTest { @Rule diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAIConfigPasswordDecodingTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAIConfigPasswordDecodingTest.java deleted file mode 100644 index bdf0fb1..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/util/AAIConfigPasswordDecodingTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.openecomp.aai - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.aai.util; - -import static org.junit.Assert.assertEquals; - -import org.junit.BeforeClass; -import org.junit.Test; - -import org.openecomp.aai.exceptions.AAIException; - -public class AAIConfigPasswordDecodingTest { - - /** - * Configure. - * - * @throws AAIException the AAI exception - */ - @BeforeClass - public static void configure() throws AAIException { - System.setProperty("AJSC_HOME", "./src/test/resources/"); - System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");; //fake prop file for testing - } - - /** - * Password check. - * - * @throws AAIException the AAI exception - */ - @Test - public void passwordCheck() throws AAIException { - assertEquals("password", "aaiuser123", AAIConfig.get("ecm.auth.password")); - } - -} diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAIRSyncUtilityTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAIRSyncUtilityTest.java index c15a99f..c8765f6 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/AAIRSyncUtilityTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/AAIRSyncUtilityTest.java @@ -21,9 +21,10 @@ package org.openecomp.aai.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.openecomp.aai.AAISetup; import java.io.File; import java.lang.reflect.Field; @@ -38,14 +39,10 @@ import java.util.List; import java.util.StringTokenizer; import java.util.UUID; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.openecomp.aai.exceptions.AAIException; +import static org.junit.Assert.*; @Ignore -public class AAIRSyncUtilityTest { +public class AAIRSyncUtilityTest extends AAISetup { AAIRSyncUtility syncUtil; AAIRSyncUtility syncUtilOmitDoCommand; @@ -53,12 +50,6 @@ public class AAIRSyncUtilityTest { String hostName; String transId = UUID.randomUUID().toString(); - @BeforeClass - public static void configure() throws AAIException { - System.setProperty("AJSC_HOME", "./src/test/resources/"); - System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");; //fake prop file for testing - } - /** * Initialize. */ diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java index 356010a..860c56c 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java @@ -20,13 +20,13 @@ package org.openecomp.aai.util; -import static org.junit.Assert.assertEquals; - import org.junit.Rule; import org.junit.Test; import org.powermock.modules.agent.PowerMockAgent; import org.powermock.modules.junit4.rule.PowerMockRule; +import static org.junit.Assert.assertEquals; + public class DataConversionHelperTest { @Rule diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DbTestConfig.java b/aai-resources/src/test/java/org/openecomp/aai/util/DbTestConfig.java index 4f84519..20a4307 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/DbTestConfig.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/DbTestConfig.java @@ -20,17 +20,9 @@ package org.openecomp.aai.util; -import java.util.Date; -import java.util.Enumeration; -import java.util.Properties; -import java.util.TimerTask; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Timer; +import java.io.*; import java.net.InetAddress; +import java.util.*; public class DbTestConfig { diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DbTestFileWatcher.java b/aai-resources/src/test/java/org/openecomp/aai/util/DbTestFileWatcher.java index 05a4cfe..55caba8 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/DbTestFileWatcher.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/DbTestFileWatcher.java @@ -20,8 +20,8 @@ package org.openecomp.aai.util; -import java.util.*; -import java.io.*; +import java.io.File; +import java.util.TimerTask; public abstract class DbTestFileWatcher extends TimerTask { private long timeStamp; diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DbTestProcessBuilder.java b/aai-resources/src/test/java/org/openecomp/aai/util/DbTestProcessBuilder.java index 8d8ebe0..306e46e 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/DbTestProcessBuilder.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/DbTestProcessBuilder.java @@ -20,11 +20,7 @@ package org.openecomp.aai.util; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.nio.file.attribute.FileTime; import java.text.SimpleDateFormat; import java.util.Arrays; diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/HbaseSaltPrefixerTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/HbaseSaltPrefixerTest.java index 4e19c35..ba15e00 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/HbaseSaltPrefixerTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/HbaseSaltPrefixerTest.java @@ -20,10 +20,10 @@ package org.openecomp.aai.util; -import static org.junit.Assert.*; - import org.junit.Test; +import static org.junit.Assert.assertTrue; + public class HbaseSaltPrefixerTest { /** diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java index e1fb24a..96150da 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java @@ -20,14 +20,14 @@ package org.openecomp.aai.util; -import static org.junit.Assert.*; +import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.Test; +import static org.junit.Assert.assertTrue; public class JettyObfuscationConversionCommandLineUtilTest { -- cgit 1.2.3-korg