5411cec852a4a6fd9088a2192819f8847c078840
[vfc/nfvo/wfengine.git] /
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.export;
13
14 import java.io.IOException;
15 import java.io.OutputStream;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import javax.ws.rs.WebApplicationException;
20 import javax.ws.rs.core.StreamingOutput;
21 import javax.xml.bind.JAXBException;
22
23 import org.apache.commons.io.output.NullOutputStream;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.eclipse.winery.common.ids.definitions.ServiceTemplateId;
28 import org.eclipse.winery.repository.PrefsTestEnabledGitBackedRepository;
29 import org.eclipse.winery.repository.backend.Repository;
30 import org.eclipse.winery.repository.backend.filebased.GitBasedRepository;
31
32 public class TestToscaExporter {
33         
34         //private static final TOSCAExportUtil toscaExporter = new TOSCAExportUtil();
35         private static final CSARExporter csarExporter = new CSARExporter();
36         
37         private static final ServiceTemplateId serviceTemplateId = new ServiceTemplateId("http://www.example.com/tosca/ServiceTemplates/Moodle", "Moodle", false);
38         
39         
40         /**
41          * Quick hack as we currently don't have a dedicated test service template
42          */
43         @BeforeClass
44         public static void setServiceTemplateId() throws Exception {
45                 // Initialize preferences
46                 // We do not need them, but constructing them has the side effect that Repository.INSTANCE is != null
47                 new PrefsTestEnabledGitBackedRepository();
48         }
49         
50         @Before
51         public void setRevision() throws Exception {
52                 ((GitBasedRepository) Repository.INSTANCE).setRevisionTo("97fa997b92965d8bc84e86274b0203f1db7495c5");
53         }
54         
55         @Test
56         public void checkTOSCAExport() throws Exception {
57                 @SuppressWarnings("unused")
58                 StreamingOutput so = new StreamingOutput() {
59                         
60                         @Override
61                         public void write(OutputStream output) throws IOException, WebApplicationException {
62                                 TOSCAExportUtil exporter = new TOSCAExportUtil();
63                                 // we include everything related
64                                 Map<String, Object> conf = new HashMap<>();
65                                 try {
66                                         exporter.exportTOSCA(TestToscaExporter.serviceTemplateId, output, conf);
67                                 } catch (JAXBException e) {
68                                         throw new WebApplicationException(e);
69                                 }
70                         }
71                 };
72                 
73                 // TODO: check output contained in SO
74         }
75         
76         @Test
77         public void checkCSARExport() throws Exception {
78                 NullOutputStream out = new NullOutputStream();
79                 TestToscaExporter.csarExporter.writeCSAR(TestToscaExporter.serviceTemplateId, out);
80         }
81 }