aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.generators.ia/src/test/java/org/eclipse/winery/generators/ia/Test.java
blob: 73d4127a0b2264cfc6a439c3ff8224dbc70b423f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*******************************************************************************
 * Copyright (c) 2013 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     Tobias Binz - initial API and implementation
 *******************************************************************************/
package org.eclipse.winery.generators.ia;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;

import org.eclipse.winery.model.tosca.ObjectFactory;
import org.eclipse.winery.model.tosca.TInterface;
import org.eclipse.winery.model.tosca.TNodeType;
import org.eclipse.winery.model.tosca.TOperation;
import org.eclipse.winery.model.tosca.TOperation.InputParameters;
import org.eclipse.winery.model.tosca.TOperation.OutputParameters;
import org.eclipse.winery.model.tosca.TParameter;
import org.junit.BeforeClass;

public class Test {
	
	private static Path WORKING_DIR;
	
	
	@BeforeClass
	public static void initializeWorkingDir() throws IOException {
		Test.WORKING_DIR = Files.createTempDirectory("IAGenerator");
	}
	
	@org.junit.Test
	public void testInOut() throws MalformedURLException {
		ObjectFactory f = new ObjectFactory();
		
		TInterface tinterface = f.createTInterface();
		tinterface.setName("http://www.example.org/interfaces/lifecycle");
		
		TOperation op1 = f.createTOperation();
		op1.setName("Op1InOut");
		tinterface.getOperation().add(op1);
		InputParameters op1InputParameters = f.createTOperationInputParameters();
		
		TParameter op1ip1 = f.createTParameter();
		op1ip1.setName("op1ip1");
		op1ip1.setType("xs:string");
		op1InputParameters.getInputParameter().add(op1ip1);
		TParameter op1ip2 = f.createTParameter();
		op1ip2.setName("op1ip2");
		op1ip2.setType("xs:string");
		op1InputParameters.getInputParameter().add(op1ip2);
		op1.setInputParameters(op1InputParameters);
		
		OutputParameters op1OutputParameters = f.createTOperationOutputParameters();
		TParameter op1op1 = f.createTParameter();
		op1op1.setName("op1op1");
		op1op1.setType("xs:string");
		op1OutputParameters.getOutputParameter().add(op1op1);
		TParameter op1op2 = f.createTParameter();
		op1op2.setName("op1op2");
		op1op1.setType("xs:string");
		op1OutputParameters.getOutputParameter().add(op1op2);
		op1.setOutputParameters(op1OutputParameters);
		
		TNodeType nodeType = f.createTNodeType();
		nodeType.setName("test");
		nodeType.setTargetNamespace("http://asd.com");
		
		Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", Test.WORKING_DIR.toFile());
		File generateProject = gen.generateProject();
		System.out.println(generateProject);
	}
	
	@org.junit.Test
	public void testMultipleOperationsInOrOut() throws MalformedURLException {
		ObjectFactory f = new ObjectFactory();
		
		TInterface tinterface = f.createTInterface();
		tinterface.setName("TestInOrOut");
		
		TOperation opIn = f.createTOperation();
		opIn.setName("OpIn");
		tinterface.getOperation().add(opIn);
		
		InputParameters op1InputParameters = f.createTOperationInputParameters();
		TParameter op1ip1 = f.createTParameter();
		op1ip1.setName("op1ip1");
		op1ip1.setType("xs:string");
		op1InputParameters.getInputParameter().add(op1ip1);
		TParameter op1ip2 = f.createTParameter();
		op1ip2.setName("op1ip2");
		op1ip2.setType("xs:string");
		op1InputParameters.getInputParameter().add(op1ip2);
		opIn.setInputParameters(op1InputParameters);
		
		TOperation opOut = f.createTOperation();
		opOut.setName("OpOut");
		tinterface.getOperation().add(opOut);
		
		OutputParameters op1OutputParameters = f.createTOperationOutputParameters();
		TParameter op1op1 = f.createTParameter();
		op1op1.setName("op1op1");
		op1op1.setType("xs:string");
		op1OutputParameters.getOutputParameter().add(op1op1);
		TParameter op1op2 = f.createTParameter();
		op1op2.setName("op1op2");
		op1op1.setType("xs:string");
		op1OutputParameters.getOutputParameter().add(op1op2);
		opOut.setOutputParameters(op1OutputParameters);
		
		TNodeType nodeType = f.createTNodeType();
		nodeType.setName("test");
		nodeType.setTargetNamespace("http://asd.com");
		
		Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", Test.WORKING_DIR.toFile());
		File generateProject = gen.generateProject();
		System.out.println(generateProject);
	}
	
	@org.junit.Test
	public void testNoParams() throws MalformedURLException {
		ObjectFactory f = new ObjectFactory();
		
		TInterface tinterface = f.createTInterface();
		tinterface.setName("TestNoParams");
		
		TOperation opIn = f.createTOperation();
		opIn.setName("OpNoParams");
		tinterface.getOperation().add(opIn);
		
		TNodeType nodeType = f.createTNodeType();
		nodeType.setName("test");
		nodeType.setTargetNamespace("http://asd.com");
		
		Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", Test.WORKING_DIR.toFile());
		File generateProject = gen.generateProject();
		System.out.println(generateProject);
	}
	
}