X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=mod%2Fgenprocessor%2Fsrc%2Ftest%2Fjava%2Fsandbox%2FAppTest.java;h=a4d58bc0b9010a52cb349e4c8939498a5fd07edd;hb=1e5a6e041efef87d43a182b54d4b01f4ae87355c;hp=d6a1ca35212e64ebb52b3d361c5107ffd376f998;hpb=95855b69835177954e185f171af2f0aea3b3d3f3;p=dcaegen2%2Fplatform.git diff --git a/mod/genprocessor/src/test/java/sandbox/AppTest.java b/mod/genprocessor/src/test/java/sandbox/AppTest.java index d6a1ca3..a4d58bc 100644 --- a/mod/genprocessor/src/test/java/sandbox/AppTest.java +++ b/mod/genprocessor/src/test/java/sandbox/AppTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2022 Huawei. 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. @@ -20,6 +21,7 @@ package sandbox; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.FileWriter; @@ -28,12 +30,16 @@ import java.io.Writer; import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; +import javassist.ClassPool; +import javassist.CtClass; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processor.ProcessSession; @@ -50,10 +56,13 @@ import org.onap.dcae.genprocessor.CompSpec; import org.onap.dcae.genprocessor.DCAEProcessor; import org.onap.dcae.genprocessor.OnboardingAPIClient; import org.onap.dcae.genprocessor.Utils; +import org.onap.dcae.genprocessor.CompList; +import org.onap.dcae.genprocessor.ProcessorBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** * Unit test for simple App. */ @@ -78,6 +87,28 @@ public class AppTest { CompSpec cs = new CompSpec(); cs.unpackSelf(mx); assertEquals(Utils.formatNameForJar(cs), "SomeJar-2.0"); + try { + CompSpec.loadComponentSpec(new File("sandbox/temp.txt")); + } catch (RuntimeException e) { + // expected case + return; + } + fail("Exception is not thrown"); + } + + @Test + public void testGetNameForJavaClass() { + CompList.CompShort compShort = new CompList.CompShort(); + compShort.name = "test"; + compShort.getNameForJavaClass(); + compShort.componentUrl = "6:invalidURI"; + try { + compShort.getComponentUrlAsURI(); + } catch (RuntimeException e) { + // expected case + return; + } + fail("Exception is not thrwon"); } @@ -174,5 +205,32 @@ public class AppTest { App.main(new String[] { "load" }); /* gen case */ App.main(new String[] { "gen" }); + + URL[] jarURLs = new URL[1]; + try { + App.loadFromJars(jarURLs); + } catch (NullPointerException e) { + // expected case + return; + } + fail("Exception is not thrown"); + } + + @Test + public void testAddMethod() { + try { + ClassPool pool = ClassPool.getDefault(); + CtClass base = pool.get(DCAEProcessor.class.getName()); + + CtClass cc = pool.makeClass(String.format("org.onap.dcae.%s", DCAEProcessor.class)); + cc.setSuperclass(base); + + ProcessorBuilder.addMethod(cc, "test"); + } catch (Exception e) { + // expected case + return; + } + fail("Exception is not thrown"); } } +