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/client-kit | |
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/client-kit')
5 files changed, 297 insertions, 0 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 + |