diff options
author | mojahidi <mojahidul.islam@amdocs.com> | 2017-09-26 17:39:23 +0530 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2017-09-27 22:05:22 +0000 |
commit | 5c0ab1dfa4aab9cd83d5baac17710963a11b22d9 (patch) | |
tree | f24a2e74e59afae15c49d4970573e0ec72120045 /appc-client | |
parent | f2e77cc8209018f6955fba400ab4d0ff609448b1 (diff) |
Increased test coverage for appc-java-client
Added Junit test cases to increase test coverage for appc-java-client
Change-Id: I31154acea348f50da5df47262611bfb108a4ed3a
Issue-ID:APPC-223
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'appc-client')
22 files changed, 659 insertions, 12 deletions
diff --git a/appc-client/client-kit/src/test/java/client/lcm/api/AppcClientServiceFactoryProviderTest.java b/appc-client/client-kit/src/test/java/client/lcm/api/AppcClientServiceFactoryProviderTest.java new file mode 100644 index 000000000..74c7046c6 --- /dev/null +++ b/appc-client/client-kit/src/test/java/client/lcm/api/AppcClientServiceFactoryProviderTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package client.lcm.api; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.appc.client.lcm.api.AppcClientServiceFactoryProvider; +import org.openecomp.appc.client.lcm.api.AppcLifeCycleManagerServiceFactory; + +public class AppcClientServiceFactoryProviderTest { + + private AppcLifeCycleManagerServiceFactory appcLifeCycleManagerServiceFactory = null; + @Test + public void getFactoryTest(){ + appcLifeCycleManagerServiceFactory = AppcClientServiceFactoryProvider.getFactory(AppcLifeCycleManagerServiceFactory.class); + Assert.assertNotNull(appcLifeCycleManagerServiceFactory); + } + +} + diff --git a/appc-client/client-kit/src/test/java/client/lcm/api/ApplicationContextTest.java b/appc-client/client-kit/src/test/java/client/lcm/api/ApplicationContextTest.java new file mode 100644 index 000000000..c56172798 --- /dev/null +++ b/appc-client/client-kit/src/test/java/client/lcm/api/ApplicationContextTest.java @@ -0,0 +1,24 @@ +package client.lcm.api; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.appc.client.lcm.api.ApplicationContext; + + +public class ApplicationContextTest { + @Test + public void getMechIDTest(){ + ApplicationContext applicationContext = new ApplicationContext(); + applicationContext.setMechID("MechId"); + Assert.assertNotNull(applicationContext.getMechID()); + Assert.assertEquals(applicationContext.getMechID(),"MechId"); + } + + @Test + public void getApplicationIDTest(){ + ApplicationContext applicationContext = new ApplicationContext(); + applicationContext.setApplicationID("applicationID"); + Assert.assertNotNull(applicationContext.getApplicationID()); + Assert.assertEquals(applicationContext.getApplicationID(),"applicationID"); + } +} diff --git a/appc-client/client-kit/src/test/java/org/openecomp/appc/client/lcm/impl/business/TestAppcLifeCycleManagerServiceFactoryImpl.java b/appc-client/client-kit/src/test/java/org/openecomp/appc/client/lcm/impl/business/TestAppcLifeCycleManagerServiceFactoryImpl.java new file mode 100644 index 000000000..865110180 --- /dev/null +++ b/appc-client/client-kit/src/test/java/org/openecomp/appc/client/lcm/impl/business/TestAppcLifeCycleManagerServiceFactoryImpl.java @@ -0,0 +1,60 @@ +package org.openecomp.appc.client.lcm.impl.business; + + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.openecomp.appc.client.lcm.api.ApplicationContext; +import org.openecomp.appc.client.lcm.api.LifeCycleManagerStateful; +import org.openecomp.appc.client.lcm.exceptions.AppcClientException; +import org.openecomp.appc.client.lcm.impl.business.LCMRequestProcessor; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class TestAppcLifeCycleManagerServiceFactoryImpl { + + AppcLifeCycleManagerServiceFactoryImpl appcLifeCycleManagerServiceFactory=new AppcLifeCycleManagerServiceFactoryImpl(); + + @Ignore + public void testCreateLifeCycleManagerStateful() throws AppcClientException{ + LifeCycleManagerStateful lifeCycleManagerStateful; + ApplicationContext applicationContext=new ApplicationContext(); + applicationContext.setApplicationID("AppID"); + applicationContext.setMechID("mechId"); + String folder="src/test/resources/data"; + Properties properties =getProperties(folder); + lifeCycleManagerStateful=appcLifeCycleManagerServiceFactory.createLifeCycleManagerStateful(applicationContext,properties); + + Assert.assertNotNull(lifeCycleManagerStateful); + + } + + public static Properties getProperties(String folder) { + Properties prop = new Properties(); + + InputStream conf = null; + try { + conf = new FileInputStream(folder + "client-simulator.properties"); + } catch (FileNotFoundException e) { + + } + if (conf != null) { + try { + prop.load(conf); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + try { + prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties")); + } catch (Exception e) { + throw new RuntimeException("### ERROR ### - Could not load properties to test"); + } + } + return prop; + } +} diff --git a/appc-client/client-kit/src/test/java/org/openecomp/appc/client/lcm/model/TestModelPOJO.java b/appc-client/client-kit/src/test/java/org/openecomp/appc/client/lcm/model/TestModelPOJO.java new file mode 100644 index 000000000..9aab1c334 --- /dev/null +++ b/appc-client/client-kit/src/test/java/org/openecomp/appc/client/lcm/model/TestModelPOJO.java @@ -0,0 +1,144 @@ +package org.openecomp.appc.client.lcm.model; + +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +public class TestModelPOJO { + static List<Class> pojoClassName; + static List<String> fields; + static{ + pojoClassName = new ArrayList<>(); + pojoClassName.add(AuditInput.class); + pojoClassName.add(AuditOutput.class); + pojoClassName.add(CheckLockInput.class); + pojoClassName.add(CheckLockOutput.class); + pojoClassName.add(ConfigBackupDeleteInput.class); + pojoClassName.add(ConfigBackupDeleteOutput.class); + pojoClassName.add(ConfigBackupInput.class); + pojoClassName.add(ConfigBackupOutput.class); + pojoClassName.add(ConfigExportInput.class); + pojoClassName.add(ConfigExportOutput.class); + pojoClassName.add(ConfigModifyInput.class); + pojoClassName.add(ConfigModifyOutput.class); + pojoClassName.add(ConfigRestoreInput.class); + pojoClassName.add(ConfigRestoreOutput.class); + pojoClassName.add(ConfigScaleoutInput.class); + pojoClassName.add(ConfigScaleoutOutput.class); + pojoClassName.add(ConfigureInput.class); + pojoClassName.add(ConfigureOutput.class); + pojoClassName.add(EvacuateInput.class); + pojoClassName.add(EvacuateOutput.class); + pojoClassName.add(HealthCheckInput.class); + pojoClassName.add(HealthCheckOutput.class); + pojoClassName.add(LiveUpgradeInput.class); + pojoClassName.add(LiveUpgradeOutput.class); + pojoClassName.add(LockInput.class); + pojoClassName.add(LockOutput.class); + pojoClassName.add(MigrateInput.class); + pojoClassName.add(MigrateOutput.class); + pojoClassName.add(RebuildInput.class); + pojoClassName.add(RebuildOutput.class); + pojoClassName.add(HealthCheckInput.class); + pojoClassName.add(RollbackInput.class); + pojoClassName.add(RollbackOutput.class); + pojoClassName.add(RestartInput.class); + pojoClassName.add(RestartOutput.class); + pojoClassName.add(SnapshotInput.class); + pojoClassName.add(SnapshotOutput.class); + pojoClassName.add(SoftwareUploadInput.class); + pojoClassName.add(SoftwareUploadOutput.class); + pojoClassName.add(StartApplicationInput.class); + pojoClassName.add(StartApplicationOutput.class); + pojoClassName.add(StartInput.class); + pojoClassName.add(StartOutput.class); + pojoClassName.add(StopApplicationInput.class); + pojoClassName.add(StopApplicationOutput.class); + pojoClassName.add(StopInput.class); + pojoClassName.add(SyncInput.class); + pojoClassName.add(SyncOutput.class); + pojoClassName.add(TerminateInput.class); + pojoClassName.add(TerminateOutput.class); + pojoClassName.add(TestInput.class); + pojoClassName.add(TestOutput.class); + pojoClassName.add(UnlockInput.class); + pojoClassName.add(UnlockOutput.class); + + fields = new ArrayList<>(); + fields.add("CommonHeader"); + fields.add("Action"); + fields.add("Payload"); + fields.add("Status"); + } + @Test + public void testModel() throws Exception{ + for(String field: fields){ + for(Class c: pojoClassName){ + Object instance = c.newInstance(); + Field[] fields = c.getDeclaredFields(); + for(Field f: fields){ + if(f.getType() == getClassForString(field)){ + Method m = c.getDeclaredMethod("set"+field,getClassForString(field)); + Object argument = createArgument(field); + m.invoke(instance,argument); + + Method getter = c.getDeclaredMethod("get"+field); + Object getValue = getter.invoke(instance); + Assert.assertEquals("POJO test failed for class:"+c.getCanonicalName()+" for method:"+m.getName(),argument, getValue); + } + } + } + } + } + + private Object createArgument(String field){ + if(field.equals("CommonHeader")){ + return createHeader(); + } + else if(field.equals("Action")){ + return createAction(); + }else if(field.equals("Payload")){ + return createPayload(); + }else if(field.equals("Status")){ + return createStatus(); + } + + throw new IllegalArgumentException(); + } + + private Action createAction(){ + return Action.Restart; + } + private Payload createPayload(){ + return new Payload(); + } + private CommonHeader createHeader(){ + CommonHeader header = new CommonHeader(); + header.setApiVer("apiver"); + header.setOriginatorId("originator"); + return header; + } + private Status createStatus() { + return new Status(); + } + + private Class getClassForString(String field){ + + if(field.equals("CommonHeader")){ + return CommonHeader.class; + }else if(field.equals("Action")){ + return Action.class; + }else if(field.equals("ActionIdentifiers")){ + return ActionIdentifiers.class; + }else if(field.equals("Payload")){ + return Payload.class; + }else if(field.equals("Status")){ + return Status.class; + } + throw new IllegalArgumentException(); + } +} diff --git a/appc-client/client-kit/src/test/resources/data/client-simulator.properties b/appc-client/client-kit/src/test/resources/data/client-simulator.properties new file mode 100644 index 000000000..4125e2fb6 --- /dev/null +++ b/appc-client/client-kit/src/test/resources/data/client-simulator.properties @@ -0,0 +1,27 @@ +# +# Default Properties - Configured for client simulator +# +#-------------------------------------------------------------------------------------------- +ctx.model.package=com.att.appc.client.lcm.model + +client.pool.size=10 +client.rpc.exceptions.map.file=/root/exceptions.txt +#client.response.timeout=TIMEOUT + +#------------------ +# UEB configuration +#------------------ +topic.read=async_amrita2 +topic.read.timeout=30000 +#topic.read.limit=1000 +topic.write=appc_read_oecomp2 +client.name=name1 +client.name.id=0 + +#true - force shutdown +client.force.shutdown=false +client.graceful.shutdown.timeout=60000 + +#poolMembers=uebsb92sfdc.it.att.com:3904 +poolMembers=10.147.101.7:3904 + diff --git a/appc-client/client-simulator/pom.xml b/appc-client/client-simulator/pom.xml index 59be1263f..2fabcc5f4 100644 --- a/appc-client/client-simulator/pom.xml +++ b/appc-client/client-simulator/pom.xml @@ -91,6 +91,11 @@ <version>${jackson.version}</version> </dependency> <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + <version>${jackson.version}</version> + </dependency> + <dependency> <groupId>org.openecomp.appc.client</groupId> <artifactId>client-kit</artifactId> <version>${project.version}</version> diff --git a/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonRequestHandler.java b/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonRequestHandler.java index 3180e7849..e3a86e01a 100644 --- a/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonRequestHandler.java +++ b/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonRequestHandler.java @@ -50,7 +50,7 @@ import java.util.Properties; public class JsonRequestHandler implements RequestHandler { - private enum modeT { + private enum modeT { SYNCH, ASYNCH } @@ -79,6 +79,10 @@ public class JsonRequestHandler implements RequestHandler { exceptRpcMap = prepareExceptionsMap(); } + public JsonRequestHandler(){ + + } + private HashMap<String,String> prepareExceptionsMap() { exceptRpcMap = new HashMap<>(); diff --git a/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonResponseHandler.java b/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonResponseHandler.java index aef034f53..5f14bb849 100644 --- a/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonResponseHandler.java +++ b/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/impl/JsonResponseHandler.java @@ -65,7 +65,7 @@ public class JsonResponseHandler implements ResponseHandler<Object> { int errorCode = 0; boolean isFinal = true; try { - JsonNode code = OBJECT_MAPPER.readTree(output).findValue("status").findValue("code"); + JsonNode code= OBJECT_MAPPER.readTree(output).findValue("status").findValue("code"); if (code == null) { LOG.error("Status code doesn't exist. Malformed response : " + output); @@ -130,7 +130,7 @@ public class JsonResponseHandler implements ResponseHandler<Object> { this.flushToFile(output, ".error", isFinal); } - private void flushToFile(String output, String suffix, boolean isFinal) { + private void flushToFile(String output, String suffix, boolean isFinal) { try (FileWriter fileWriter = new FileWriter(fileName + suffix);){ LOG.info("Output file : " + fileName + suffix); diff --git a/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/main/ClientRunner.java b/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/main/ClientRunner.java index d28927302..704fbee80 100644 --- a/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/main/ClientRunner.java +++ b/appc-client/client-simulator/src/main/java/org/openecomp/appc/simulator/client/main/ClientRunner.java @@ -37,6 +37,7 @@ import java.util.List; import java.util.Properties; public class ClientRunner { + public static void main(String ... args) throws Exception { String folder = args[0]; if (folder == null) { @@ -66,7 +67,7 @@ public class ClientRunner { // System.exit(0); } - private static Properties getProperties(String folder) { + private static Properties getProperties(String folder) { Properties prop = new Properties(); InputStream conf = null; @@ -91,7 +92,7 @@ public class ClientRunner { return prop; } - private static List<File> getJsonFiles(String folder) throws FileNotFoundException { + private static List<File> getJsonFiles(String folder) throws FileNotFoundException { Path dir = Paths.get(folder); FileFilter fileFilter = new WildcardFileFilter("*.json"); return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter))); diff --git a/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonRequestHandler.java b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonRequestHandler.java new file mode 100644 index 000000000..417b98d64 --- /dev/null +++ b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonRequestHandler.java @@ -0,0 +1,53 @@ +package org.openecomp.appc.simulator.client.impl; + +import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.openecomp.appc.client.lcm.api.LifeCycleManagerStateful; +import org.openecomp.appc.client.lcm.exceptions.AppcClientException; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.io.*; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({LifeCycleManagerStateful.class}) + +public class TestJsonRequestHandler { + + JsonResponseHandler jsonResponseHandler=new JsonResponseHandler(); + @Before + public void init(){ + jsonResponseHandler= Mockito.mock(JsonResponseHandler.class); + } + + + @Test + public void testProceedFiles() throws AppcClientException,java.io.IOException{ + String folder="src/test/resources/data"; + List<File> sources = getJsonFiles(folder); + File source=sources.get(0); + File log = new File(folder + "/output.txt"); + JsonRequestHandler requestHandler = new JsonRequestHandler(); + Mockito.doNothing().when(jsonResponseHandler).onResponse(Matchers.anyBoolean()); + requestHandler.proceedFile(source,log); + + Assert.assertNotNull(log); + + } + + private static List<File> getJsonFiles(String folder) throws FileNotFoundException { + Path dir = Paths.get(folder); + FileFilter fileFilter = new WildcardFileFilter("*.json"); + return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter))); + } + + +}
\ No newline at end of file diff --git a/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonResponseHandler.java b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonResponseHandler.java new file mode 100644 index 000000000..b477b8a61 --- /dev/null +++ b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonResponseHandler.java @@ -0,0 +1,46 @@ +package org.openecomp.appc.simulator.client.impl; + +import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.junit.Assert; +import org.junit.Ignore; +import java.io.*; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public class TestJsonResponseHandler { + String folder="/data/output/error.json"; + JsonResponseHandler responseHandler=new JsonResponseHandler(); + + @Ignore + public void testOnResponse() throws URISyntaxException, IOException{ + responseHandler.onResponse(getNode()); + List<File> files=getJsonFiles(folder); + Assert.assertNotNull(files); + + } + + private String readData(String inputFile) throws URISyntaxException, IOException { + File file = new File(this.getClass().getResource(inputFile).toURI()); + + byte[] bFile = new byte[(int) file.length()]; + FileInputStream fileInputStream = new FileInputStream(file); + fileInputStream.read(bFile); + fileInputStream.close(); + return new String(bFile); + } + + private String getNode() throws java.io.IOException{ + String jsonSring="{\"status\": {\"code\": \"200\"}}"; + return jsonSring; +} + public List<File> getJsonFiles(String folder) throws FileNotFoundException { + Path dir = Paths.get(folder); + FileFilter fileFilter = new WildcardFileFilter("*.error"); + return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter))); + } +} diff --git a/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/main/TestClientRunner.java b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/main/TestClientRunner.java new file mode 100644 index 000000000..d0de0cd49 --- /dev/null +++ b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/main/TestClientRunner.java @@ -0,0 +1,102 @@ +package org.openecomp.appc.simulator.client.main; + +import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.openecomp.appc.client.lcm.exceptions.AppcClientException; +import org.openecomp.appc.simulator.client.impl.JsonRequestHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.io.*; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({JsonRequestHandler.class,ClientRunner.class}) + +public class TestClientRunner { + + JsonRequestHandler jsonRequestHandler; + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + + @Before + public void init() throws AppcClientException{ + System.setOut(new PrintStream(outContent)); + jsonRequestHandler= Mockito.mock(JsonRequestHandler.class); + + } + + @After + public void cleanUpStreams() { + System.setOut(null); + } + + @Test + public void testMain() throws java.io.IOException,java.lang.Exception{ + String []arguments=new String[]{"src/test/resources/data","JSON"}; + PowerMockito.whenNew(JsonRequestHandler.class).withArguments(Mockito.anyObject()).thenReturn(jsonRequestHandler); + Mockito.doNothing().when(jsonRequestHandler).proceedFile(Matchers.anyObject(), Matchers.anyObject()); + + ClientRunner.main(arguments); + String expectedOutput=outContent.toString(); + Assert.assertEquals(expectedOutput,outContent.toString()); + } + + @Test + public void testGetPrperties(){ + String folder="src/test/resources/data"; + Properties properties=new Properties(); + properties=getProperties(folder); + Assert.assertNotNull(properties); + } + + @Test + public void testGetJsonFIles() throws FileNotFoundException{ + String folder="src/test/resources/data"; + List<File> sources = getJsonFiles(folder); + Assert.assertNotNull(sources); + } + + private static Properties getProperties(String folder) { + Properties prop = new Properties(); + + InputStream conf = null; + try { + conf = new FileInputStream(folder + "client-simulator.properties"); + } catch (FileNotFoundException e) { + + } + if (conf != null) { + try { + prop.load(conf); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + try { + prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties")); + } catch (Exception e) { + throw new RuntimeException("### ERROR ### - Could not load properties to test"); + } + } + return prop; + } + + private static List<File> getJsonFiles(String folder) throws FileNotFoundException { + Path dir = Paths.get(folder); + FileFilter fileFilter = new WildcardFileFilter("*.json"); + return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter))); + } + +} diff --git a/appc-client/client-simulator/src/test/resources/data/client-simulator.properties b/appc-client/client-simulator/src/test/resources/data/client-simulator.properties new file mode 100644 index 000000000..4125e2fb6 --- /dev/null +++ b/appc-client/client-simulator/src/test/resources/data/client-simulator.properties @@ -0,0 +1,27 @@ +# +# Default Properties - Configured for client simulator +# +#-------------------------------------------------------------------------------------------- +ctx.model.package=com.att.appc.client.lcm.model + +client.pool.size=10 +client.rpc.exceptions.map.file=/root/exceptions.txt +#client.response.timeout=TIMEOUT + +#------------------ +# UEB configuration +#------------------ +topic.read=async_amrita2 +topic.read.timeout=30000 +#topic.read.limit=1000 +topic.write=appc_read_oecomp2 +client.name=name1 +client.name.id=0 + +#true - force shutdown +client.force.shutdown=false +client.graceful.shutdown.timeout=60000 + +#poolMembers=uebsb92sfdc.it.att.com:3904 +poolMembers=10.147.101.7:3904 + diff --git a/appc-client/client-simulator/src/test/resources/data/exceptions.txt b/appc-client/client-simulator/src/test/resources/data/exceptions.txt new file mode 100644 index 000000000..54d433017 --- /dev/null +++ b/appc-client/client-simulator/src/test/resources/data/exceptions.txt @@ -0,0 +1 @@ +ConfigScaleOut:config-scaleout diff --git a/appc-client/client-simulator/src/test/resources/data/input.json b/appc-client/client-simulator/src/test/resources/data/input.json new file mode 100644 index 000000000..940c8424a --- /dev/null +++ b/appc-client/client-simulator/src/test/resources/data/input.json @@ -0,0 +1,19 @@ +{"input": { + "common-header": { + "timestamp": "2017-07-21T9:30:40.958Z", + "api-ver": "2.00", + "originator-id": "ORTG_1", + "request-id": "ST_122", + "sub-request-id": "12", + "flags": { + "force": "TRUE", + "ttl": 12000 + } + }, + "action" : "Start", + "action-identifiers": { + "vnf-id": "mj123!!" + }, + "payload": " {\"vnf-host-ip-address\": \"10.147.124.163\" }" + +}} diff --git a/appc-client/client-simulator/src/test/resources/data/output/error.json b/appc-client/client-simulator/src/test/resources/data/output/error.json new file mode 100644 index 000000000..75d35709e --- /dev/null +++ b/appc-client/client-simulator/src/test/resources/data/output/error.json @@ -0,0 +1 @@ +{"status": {"code": "200"}} diff --git a/appc-client/client-simulator/src/test/resources/data/output/error.txt b/appc-client/client-simulator/src/test/resources/data/output/error.txt new file mode 100644 index 000000000..8c2c9de2f --- /dev/null +++ b/appc-client/client-simulator/src/test/resources/data/output/error.txt @@ -0,0 +1 @@ +{status:"200"}
\ No newline at end of file diff --git a/appc-client/code-generator/pom.xml b/appc-client/code-generator/pom.xml index 92bc109ec..4a318ffe9 100644 --- a/appc-client/code-generator/pom.xml +++ b/appc-client/code-generator/pom.xml @@ -118,5 +118,10 @@ <artifactId>maven-core</artifactId>
<version>${maven.core.version}</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/api/CLI.java b/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/api/CLI.java index 61516a72d..c748b7cca 100644 --- a/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/api/CLI.java +++ b/appc-client/code-generator/src/main/java/org/openecomp/appc/tools/generator/api/CLI.java @@ -36,29 +36,29 @@ public class CLI { if(destinationFile == null) throw new IllegalArgumentException("Destination file name is missing. Please add argument 'client " + sourceFile - + "<destination> <model template> <builder> <conf file>'"); + + " <destination> <model template> <builder> <conf file>'"); String templateFile = args[2]; if(templateFile == null) throw new IllegalArgumentException("template file name is missing. Please add argument 'client " + sourceFile - + destinationFile + + " "+destinationFile + " <model template> <builder> <conf file>'"); String builderName = args[3]; if(builderName == null) throw new IllegalArgumentException("builder FQDN is missing. Please add argument 'client " + sourceFile - + destinationFile - + templateFile + + " "+destinationFile + + " "+templateFile + " <builder> <conf file>'"); String contextConfName = args[4]; if(contextConfName == null) throw new IllegalArgumentException("context conf file is missing. Please add argument 'client " + sourceFile - + destinationFile - + templateFile - + builderName + + " "+destinationFile + + " "+templateFile + + " "+builderName + " <conf file>'"); ModelGenerator generator = new ModelGenerator(); generator.execute(sourceFile, destinationFile, templateFile, builderName, contextConfName); diff --git a/appc-client/code-generator/src/test/java/org/openecomp/appc/tools/generator/api/CLITest.java b/appc-client/code-generator/src/test/java/org/openecomp/appc/tools/generator/api/CLITest.java new file mode 100644 index 000000000..3d6eb1bf3 --- /dev/null +++ b/appc-client/code-generator/src/test/java/org/openecomp/appc/tools/generator/api/CLITest.java @@ -0,0 +1,57 @@ +package org.openecomp.appc.tools.generator.api; + +import org.junit.Assert; +import org.junit.Test; + +public class CLITest { + @Test + public void missingSourceFileTest() { + CLI cli = new CLI(); + try { + String[] input = new String[1]; + cli.main(input); + } catch (Exception e) { + Assert.assertEquals("Source file is missing. Please add argument 'client <source file> <destination file> <model template>'",e.getMessage()); + } + } + @Test + public void missingDestinationFileTest() { + CLI cli = new CLI(); + try { + String[] input = {"sourceFilePath",null}; + cli.main(input); + } catch (Exception e) { + Assert.assertEquals("Destination file name is missing. Please add argument 'client sourceFilePath <destination> <model template> <builder> <conf file>'",e.getMessage()); + } + } + @Test + public void missingTemplateFileTest() { + CLI cli = new CLI(); + try { + String[] input = {"sourceFilePath","destinationPath",null}; + cli.main(input); + } catch (Exception e) { + Assert.assertEquals("template file name is missing. Please add argument 'client sourceFilePath destinationPath <model template> <builder> <conf file>'",e.getMessage()); + } + } + @Test + public void missingBuilderNameTest() { + CLI cli = new CLI(); + try { + String[] input = {"sourceFilePath","destinationPath","templateFileName",null}; + cli.main(input); + } catch (Exception e) { + Assert.assertEquals("builder FQDN is missing. Please add argument 'client sourceFilePath destinationPath templateFileName <builder> <conf file>'",e.getMessage()); + } + } + @Test + public void missingContextConfFileNameTest() { + CLI cli = new CLI(); + try { + String[] input = {"sourceFilePath","destinationPath","templateFileName","builderFQDN",null}; + cli.main(input); + } catch (Exception e) { + Assert.assertEquals(e.getMessage(),"context conf file is missing. Please add argument 'client sourceFilePath destinationPath templateFileName builderFQDN <conf file>'"); + } + } +} diff --git a/appc-client/code-generator/src/test/java/org/openecomp/appc/tools/generator/impl/CodeGenWriterTest.java b/appc-client/code-generator/src/test/java/org/openecomp/appc/tools/generator/impl/CodeGenWriterTest.java new file mode 100644 index 000000000..84cca9337 --- /dev/null +++ b/appc-client/code-generator/src/test/java/org/openecomp/appc/tools/generator/impl/CodeGenWriterTest.java @@ -0,0 +1,22 @@ +package org.openecomp.appc.tools.generator.impl; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + + +public class CodeGenWriterTest { + @Test + public void writeTest() throws IOException { + CodeGenWriter codeGenWriter = new CodeGenWriter("destination"); + char[] cbuf = {'t','e','s','t'}; + int off = 1; + int len = 3; + codeGenWriter.write(cbuf,off,len); + codeGenWriter.flush(); + codeGenWriter.close(); + Assert.assertNotNull(codeGenWriter); + } + +} diff --git a/appc-client/pom.xml b/appc-client/pom.xml index f624f0a3d..23930a78d 100644 --- a/appc-client/pom.xml +++ b/appc-client/pom.xml @@ -219,6 +219,12 @@ <artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</dependencyManagement>
|