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
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.client;
14 import java.io.IOException;
15 import java.util.Collection;
16 import java.util.List;
18 import javax.xml.namespace.QName;
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;
33 * Tests client methods with a pre-configured client stored in a local static
36 * Client creation and multiple repositories are not tested. This should be
37 * subject to other test classes.
39 * TODO: This class expects things to be existent in the namespace "test". This
40 * should be enforced in a preload.
42 @RunWith(JUnit4.class)
43 public class TestWineryRepositoryClient {
45 // private final String repositoryURI = "http://2471.de:8080/wineydev";
46 private static final String repositoryURI = "http://localhost:8080/winery";
48 private static final boolean USE_PROXY = true;
50 private static final IWineryRepositoryClient client = new WineryRepositoryClient(TestWineryRepositoryClient.USE_PROXY);
52 TestWineryRepositoryClient.client.addRepository(TestWineryRepositoryClient.repositoryURI);
56 * The namespace to put new things in. <br />
57 * TODO: Is deleted completely after testing
59 private static final String namespaceForNewArtifacts = "http://www.example.org/test/wineryclient/";
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());
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());
81 public void getAllNodeTypesWithAssociatedElements() {
82 Collection<TDefinitions> allTypes = TestWineryRepositoryClient.client.getAllTypesWithAssociatedElements(TNodeType.class);
83 Assert.assertNotNull(allTypes);
87 public void getAllRelationshipTypesWithAssociatedElements() {
88 Collection<TDefinitions> allTypes = TestWineryRepositoryClient.client.getAllTypesWithAssociatedElements(TRelationshipType.class);
89 Assert.assertNotNull(allTypes);
93 public void getPropertiesOfAllNodeTypes() {
98 public void getPropertiesOfAllRelationshipTypes() {
103 public void getTestTopologyTemplate() {
104 QName serviceTemplate = new QName("test", "test");
105 TTopologyTemplate topologyTemplate = TestWineryRepositoryClient.client.getTopologyTemplate(serviceTemplate);
106 Assert.assertNotNull(topologyTemplate);
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) {
121 public void artifactTypeForWARfiles() {
122 QName artifactType = TestWineryRepositoryClient.client.getArtifactTypeQNameForExtension("war");
123 Assert.assertNotNull("Artifact Type for .war does not exist", artifactType);
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);
132 // assure that the artifact template does not yet exist
133 // one possibility is to delete the artifact template, the other
136 QName artifactTemplateQName = new QName(TestWineryRepositoryClient.namespaceForNewArtifacts, "artifactTemplate");
137 ArtifactTemplateId atId = new ArtifactTemplateId(artifactTemplateQName);
139 // ensure that the template does not exist yet
140 TestWineryRepositoryClient.client.forceDelete(atId);
142 TestWineryRepositoryClient.client.createArtifactTemplate(artifactTemplateQName, artifactTypeQName);