Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository.client / src / test / java / org / eclipse / winery / repository / client / TestWineryRepositoryClient.java
1 /*******************************************************************************
2  * Copyright (c) 2012-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  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.client;
13
14 import java.io.IOException;
15 import java.util.Collection;
16 import java.util.List;
17
18 import javax.xml.namespace.QName;
19
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.JUnit4;
24 import org.eclipse.winery.model.tosca.TDefinitions;
25 import org.eclipse.winery.model.tosca.TEntityTemplate;
26 import org.eclipse.winery.model.tosca.TNodeType;
27 import org.eclipse.winery.model.tosca.TRelationshipType;
28 import org.eclipse.winery.model.tosca.TTopologyTemplate;
29 import org.eclipse.winery.common.ids.definitions.ArtifactTemplateId;
30 import org.eclipse.winery.common.interfaces.QNameAlreadyExistsException;
31
32 /**
33  * Tests client methods with a pre-configured client stored in a local static
34  * field.
35  * 
36  * Client creation and multiple repositories are not tested. This should be
37  * subject to other test classes.
38  * 
39  * TODO: This class expects things to be existent in the namespace "test". This
40  * should be enforced in a preload.
41  */
42 @RunWith(JUnit4.class)
43 public class TestWineryRepositoryClient {
44         
45         // private final String repositoryURI = "http://2471.de:8080/wineydev";
46         private static final String repositoryURI = "http://localhost:8080/winery";
47         
48         private static final boolean USE_PROXY = true;
49         
50         private static final IWineryRepositoryClient client = new WineryRepositoryClient(TestWineryRepositoryClient.USE_PROXY);
51         static {
52                 TestWineryRepositoryClient.client.addRepository(TestWineryRepositoryClient.repositoryURI);
53         }
54         
55         /**
56          * The namespace to put new things in. <br />
57          * TODO: Is deleted completely after testing
58          */
59         private static final String namespaceForNewArtifacts = "http://www.example.org/test/wineryclient/";
60         
61         
62         @Test
63         public void getAllNodeTypes() {
64                 Collection<TNodeType> allTypes = TestWineryRepositoryClient.client.getAllTypes(TNodeType.class);
65                 for (TNodeType type : allTypes) {
66                         Assert.assertNotNull("name is null", type.getName());
67                         Assert.assertNotNull("target namespace is null", type.getTargetNamespace());
68                 }
69         }
70         
71         @Test
72         public void getAllRelationshipTypes() {
73                 Collection<TRelationshipType> allTypes = TestWineryRepositoryClient.client.getAllTypes(TRelationshipType.class);
74                 for (TRelationshipType type : allTypes) {
75                         Assert.assertNotNull("name is null", type.getName());
76                         Assert.assertNotNull("target namespace is null", type.getTargetNamespace());
77                 }
78         }
79         
80         @Test
81         public void getAllNodeTypesWithAssociatedElements() {
82                 Collection<TDefinitions> allTypes = TestWineryRepositoryClient.client.getAllTypesWithAssociatedElements(TNodeType.class);
83                 Assert.assertNotNull(allTypes);
84         }
85         
86         @Test
87         public void getAllRelationshipTypesWithAssociatedElements() {
88                 Collection<TDefinitions> allTypes = TestWineryRepositoryClient.client.getAllTypesWithAssociatedElements(TRelationshipType.class);
89                 Assert.assertNotNull(allTypes);
90         }
91         
92         @Test
93         public void getPropertiesOfAllNodeTypes() {
94                 // TODO
95         }
96         
97         @Test
98         public void getPropertiesOfAllRelationshipTypes() {
99                 // TODO
100         }
101         
102         @Test
103         public void getTestTopologyTemplate() {
104                 QName serviceTemplate = new QName("test", "test");
105                 TTopologyTemplate topologyTemplate = TestWineryRepositoryClient.client.getTopologyTemplate(serviceTemplate);
106                 Assert.assertNotNull(topologyTemplate);
107         }
108         
109         @Test
110         public void getPropertiesOfTestTopologyTemplate() {
111                 QName serviceTemplate = new QName("test", "test");
112                 TTopologyTemplate topologyTemplate = TestWineryRepositoryClient.client.getTopologyTemplate(serviceTemplate);
113                 Assert.assertNotNull(topologyTemplate);
114                 List<TEntityTemplate> allTemplates = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
115                 for (TEntityTemplate e : allTemplates) {
116                         // TODO
117                 }
118         }
119         
120         @Test
121         public void artifactTypeForWARfiles() {
122                 QName artifactType = TestWineryRepositoryClient.client.getArtifactTypeQNameForExtension("war");
123                 Assert.assertNotNull("Artifact Type for .war does not exist", artifactType);
124         }
125         
126         @Test
127         public void createArtifactTemplate() throws IOException, QNameAlreadyExistsException {
128                 // assure that the artifact type exists
129                 QName artifactTypeQName = TestWineryRepositoryClient.client.getArtifactTypeQNameForExtension("war");
130                 Assert.assertNotNull("Artifact Type for .war does not exist", artifactTypeQName);
131                 
132                 // assure that the artifact template does not yet exist
133                 // one possibility is to delete the artifact template, the other
134                 // possibility is to
135                 
136                 QName artifactTemplateQName = new QName(TestWineryRepositoryClient.namespaceForNewArtifacts, "artifactTemplate");
137                 ArtifactTemplateId atId = new ArtifactTemplateId(artifactTemplateQName);
138                 
139                 // ensure that the template does not exist yet
140                 TestWineryRepositoryClient.client.forceDelete(atId);
141                 
142                 TestWineryRepositoryClient.client.createArtifactTemplate(artifactTemplateQName, artifactTypeQName);
143         }
144 }