2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.io.Writer;
29 import java.net.URISyntaxException;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.LinkedList;
34 import java.util.List;
37 import org.apache.nifi.components.PropertyDescriptor;
38 import org.apache.nifi.processor.ProcessContext;
39 import org.apache.nifi.processor.ProcessSession;
40 import org.apache.nifi.processor.Relationship;
41 import org.apache.nifi.processor.exception.ProcessException;
43 import org.junit.Rule;
44 import org.junit.Test;
45 import org.junit.contrib.java.lang.system.EnvironmentVariables;
46 import org.junit.rules.TemporaryFolder;
48 import org.onap.dcae.genprocessor.App;
49 import org.onap.dcae.genprocessor.CompSpec;
50 import org.onap.dcae.genprocessor.DCAEProcessor;
51 import org.onap.dcae.genprocessor.OnboardingAPIClient;
52 import org.onap.dcae.genprocessor.Utils;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
58 * Unit test for simple App.
60 public class AppTest {
61 static final Logger LOG = LoggerFactory.getLogger(AppTest.class);
64 public final EnvironmentVariables evars = new EnvironmentVariables();
67 public TemporaryFolder tfolder = new TemporaryFolder();
71 public void testUtils() {
73 assertEquals(Utils.formatNameForJavaClass("part1.a-bee"), "Part1ABee");
74 HashMap<String, String> mx = new HashMap<>();
75 mx.put("name", "SomeJar");
76 mx.put("version", "2.0");
77 mx.put("description", "desc");
78 CompSpec cs = new CompSpec();
80 assertEquals(Utils.formatNameForJar(cs), "SomeJar-2.0");
85 public void testDcaeProcessor() throws ProcessException {
86 DCAEProcessor px = new DCAEProcessor() {
87 public String getName() {
91 public String getVersion() {
95 public String getComponentId() {
99 public String getComponentUrl() {
103 protected List<PropertyDescriptor> buildSupportedPropertyDescriptors() {
104 return (new LinkedList<>());
107 protected Set<Relationship> buildRelationships() {
108 return (new HashSet<>());
111 public DCAEProcessor xxx() {
112 getSupportedPropertyDescriptors();
113 getSupportedPropertyDescriptors();
118 px.onTrigger((ProcessContext)null, (ProcessSession)null);
119 px.getRelationships();
120 px.getRelationships();
125 public void testPaths() throws InterruptedException, IOException, URISyntaxException {
126 /* some trivial cases */
127 new OnboardingAPIClient();
129 OnboardingAPIClient.getComponents("6:invalidURI");
130 } catch (OnboardingAPIClient.OnboardingAPIClientError oace) {
134 OnboardingAPIClient.getComponent(null);
135 } catch (OnboardingAPIClient.OnboardingAPIClientError oace) {
138 /* background one shot failure cases */
139 evars.clear("GENPROC_SLEEP_SEC");
140 App.main(new String[0]);
141 evars.set("GENPROC_SLEEP_SEC", "0");
142 String wdir = tfolder.newFolder("work").getPath();
143 evars.set("GENPROC_WORKING_DIR", wdir);
144 String onboardingdir = tfolder.newFolder("onboarding").getPath();
145 evars.set("GENPROC_ONBOARDING_API_HOST", (new File(onboardingdir)).toURI().toURL().toString());
146 String compfile = onboardingdir + "/compone";
147 try (Writer w = new FileWriter(compfile)) {
148 w.write("{ \"id\": \"1\", \"spec\": { \"name\": \"one-collector\","
149 + " \"version\": \"1.0.0\", \"description\": \"desc\","
150 + " \"parameters\": [{\"name\": \"p1\", \"value\": \"v1\","
151 + " \"description\": \"d1\"}], \"streams\":"
152 + " {\"publishes\":[{\"format\": \"f1\", \"version\": \"v1\","
153 + " \"type\": \"t1\", \"config_key\": \"ck1\"}],"
154 + " \"subscribes\":[{\"format\": \"f2\", \"version\": \"v2\","
155 + " \"type\": \"t2\", \"config_key\": \"ck2\"}]}},"
156 + " \"selfUrl\": \"file:" + compfile + "\"}");
158 try (Writer w = new FileWriter(onboardingdir + "/components")) {
159 w.write("{\"components\": [{\"id\": \"1\", \"name\": \"one\","
160 + " \"version\": \"1.0.0\", \"description\": \"desc\","
161 + " \"componentType\": \"apple\", \"owner\": \"John Doe\","
162 + " \"componentUrl\": \"file:" + compfile + "\","
163 + " \"whenAdded\": \"never\" }]}");
165 String indexfile = tfolder.newFile("index").getPath();
166 try (Writer w = new FileWriter(indexfile)) {
169 evars.set("GENPROC_JAR_INDEX_URL", (new File(indexfile)).toURI().toURL().toString());
170 App.main(new String[0]);
172 App.main(new String[] { "-h" });
174 App.main(new String[] { "load" });
176 App.main(new String[] { "gen" });