Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.generators.ia / src / test / java / org / eclipse / winery / generators / ia / Test.java
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
8  *
9  * Contributors:
10  *     Tobias Binz - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.generators.ia;
13
14 import java.io.File;
15 import java.io.IOException;
16 import java.net.MalformedURLException;
17 import java.net.URL;
18 import java.nio.file.Files;
19 import java.nio.file.Path;
20
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;
29
30 public class Test {
31         
32         private static Path WORKING_DIR;
33         
34         
35         @BeforeClass
36         public static void initializeWorkingDir() throws IOException {
37                 Test.WORKING_DIR = Files.createTempDirectory("IAGenerator");
38         }
39         
40         @org.junit.Test
41         public void testInOut() throws MalformedURLException {
42                 ObjectFactory f = new ObjectFactory();
43                 
44                 TInterface tinterface = f.createTInterface();
45                 tinterface.setName("http://www.example.org/interfaces/lifecycle");
46                 
47                 TOperation op1 = f.createTOperation();
48                 op1.setName("Op1InOut");
49                 tinterface.getOperation().add(op1);
50                 InputParameters op1InputParameters = f.createTOperationInputParameters();
51                 
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);
61                 
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);
72                 
73                 TNodeType nodeType = f.createTNodeType();
74                 nodeType.setName("test");
75                 nodeType.setTargetNamespace("http://asd.com");
76                 
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);
80         }
81         
82         @org.junit.Test
83         public void testMultipleOperationsInOrOut() throws MalformedURLException {
84                 ObjectFactory f = new ObjectFactory();
85                 
86                 TInterface tinterface = f.createTInterface();
87                 tinterface.setName("TestInOrOut");
88                 
89                 TOperation opIn = f.createTOperation();
90                 opIn.setName("OpIn");
91                 tinterface.getOperation().add(opIn);
92                 
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);
103                 
104                 TOperation opOut = f.createTOperation();
105                 opOut.setName("OpOut");
106                 tinterface.getOperation().add(opOut);
107                 
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);
118                 
119                 TNodeType nodeType = f.createTNodeType();
120                 nodeType.setName("test");
121                 nodeType.setTargetNamespace("http://asd.com");
122                 
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);
126         }
127         
128         @org.junit.Test
129         public void testNoParams() throws MalformedURLException {
130                 ObjectFactory f = new ObjectFactory();
131                 
132                 TInterface tinterface = f.createTInterface();
133                 tinterface.setName("TestNoParams");
134                 
135                 TOperation opIn = f.createTOperation();
136                 opIn.setName("OpNoParams");
137                 tinterface.getOperation().add(opIn);
138                 
139                 TNodeType nodeType = f.createTNodeType();
140                 nodeType.setName("test");
141                 nodeType.setTargetNamespace("http://asd.com");
142                 
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);
146         }
147         
148 }