1 /*******************************************************************************
2 * Copyright (c) 2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Tobias Binz - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.generators.ia;
15 import java.io.IOException;
16 import java.net.MalformedURLException;
18 import java.nio.file.Files;
19 import java.nio.file.Path;
21 import org.eclipse.winery.model.tosca.ObjectFactory;
22 import org.eclipse.winery.model.tosca.TInterface;
23 import org.eclipse.winery.model.tosca.TNodeType;
24 import org.eclipse.winery.model.tosca.TOperation;
25 import org.eclipse.winery.model.tosca.TOperation.InputParameters;
26 import org.eclipse.winery.model.tosca.TOperation.OutputParameters;
27 import org.eclipse.winery.model.tosca.TParameter;
28 import org.junit.BeforeClass;
32 private static Path WORKING_DIR;
36 public static void initializeWorkingDir() throws IOException {
37 Test.WORKING_DIR = Files.createTempDirectory("IAGenerator");
41 public void testInOut() throws MalformedURLException {
42 ObjectFactory f = new ObjectFactory();
44 TInterface tinterface = f.createTInterface();
45 tinterface.setName("http://www.example.org/interfaces/lifecycle");
47 TOperation op1 = f.createTOperation();
48 op1.setName("Op1InOut");
49 tinterface.getOperation().add(op1);
50 InputParameters op1InputParameters = f.createTOperationInputParameters();
52 TParameter op1ip1 = f.createTParameter();
53 op1ip1.setName("op1ip1");
54 op1ip1.setType("xs:string");
55 op1InputParameters.getInputParameter().add(op1ip1);
56 TParameter op1ip2 = f.createTParameter();
57 op1ip2.setName("op1ip2");
58 op1ip2.setType("xs:string");
59 op1InputParameters.getInputParameter().add(op1ip2);
60 op1.setInputParameters(op1InputParameters);
62 OutputParameters op1OutputParameters = f.createTOperationOutputParameters();
63 TParameter op1op1 = f.createTParameter();
64 op1op1.setName("op1op1");
65 op1op1.setType("xs:string");
66 op1OutputParameters.getOutputParameter().add(op1op1);
67 TParameter op1op2 = f.createTParameter();
68 op1op2.setName("op1op2");
69 op1op1.setType("xs:string");
70 op1OutputParameters.getOutputParameter().add(op1op2);
71 op1.setOutputParameters(op1OutputParameters);
73 TNodeType nodeType = f.createTNodeType();
74 nodeType.setName("test");
75 nodeType.setTargetNamespace("http://asd.com");
77 Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", Test.WORKING_DIR.toFile());
78 File generateProject = gen.generateProject();
79 System.out.println(generateProject);
83 public void testMultipleOperationsInOrOut() throws MalformedURLException {
84 ObjectFactory f = new ObjectFactory();
86 TInterface tinterface = f.createTInterface();
87 tinterface.setName("TestInOrOut");
89 TOperation opIn = f.createTOperation();
91 tinterface.getOperation().add(opIn);
93 InputParameters op1InputParameters = f.createTOperationInputParameters();
94 TParameter op1ip1 = f.createTParameter();
95 op1ip1.setName("op1ip1");
96 op1ip1.setType("xs:string");
97 op1InputParameters.getInputParameter().add(op1ip1);
98 TParameter op1ip2 = f.createTParameter();
99 op1ip2.setName("op1ip2");
100 op1ip2.setType("xs:string");
101 op1InputParameters.getInputParameter().add(op1ip2);
102 opIn.setInputParameters(op1InputParameters);
104 TOperation opOut = f.createTOperation();
105 opOut.setName("OpOut");
106 tinterface.getOperation().add(opOut);
108 OutputParameters op1OutputParameters = f.createTOperationOutputParameters();
109 TParameter op1op1 = f.createTParameter();
110 op1op1.setName("op1op1");
111 op1op1.setType("xs:string");
112 op1OutputParameters.getOutputParameter().add(op1op1);
113 TParameter op1op2 = f.createTParameter();
114 op1op2.setName("op1op2");
115 op1op1.setType("xs:string");
116 op1OutputParameters.getOutputParameter().add(op1op2);
117 opOut.setOutputParameters(op1OutputParameters);
119 TNodeType nodeType = f.createTNodeType();
120 nodeType.setName("test");
121 nodeType.setTargetNamespace("http://asd.com");
123 Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", Test.WORKING_DIR.toFile());
124 File generateProject = gen.generateProject();
125 System.out.println(generateProject);
129 public void testNoParams() throws MalformedURLException {
130 ObjectFactory f = new ObjectFactory();
132 TInterface tinterface = f.createTInterface();
133 tinterface.setName("TestNoParams");
135 TOperation opIn = f.createTOperation();
136 opIn.setName("OpNoParams");
137 tinterface.getOperation().add(opIn);
139 TNodeType nodeType = f.createTNodeType();
140 nodeType.setName("test");
141 nodeType.setTargetNamespace("http://asd.com");
143 Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", Test.WORKING_DIR.toFile());
144 File generateProject = gen.generateProject();
145 System.out.println(generateProject);