This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmokeTest.java
116 lines (103 loc) · 3.77 KB
/
SmokeTest.java
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
/**
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* This file is part of the Smart Developer Hub Project:
* http://www.smartdeveloperhub.org/
*
* Center for Open Middleware
* http://www.centeropenmiddleware.com/
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* Copyright (C) 2015 Center for Open Middleware.
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
* Artifact : org.smartdeveloperhub.harvesters.ci.frontend:ci-frontend-dist:0.1.0
* Bundle : ci-frontend-dist-0.1.0.war
* #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
*/
package org.smartdeveloperhub.harvesters.ci.frontend.core;
import static com.jayway.restassured.RestAssured.given;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartdeveloperhub.harvesters.ci.frontend.core.QueryHelper.ResultProcessor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.jayway.restassured.response.Response;
public class SmokeTest {
private static final Logger LOGGER=LoggerFactory.getLogger(SmokeTest.class);
protected static final String TEXT_TURTLE = "text/turtle";
protected static final int OK = 200;
protected static final String SERVICE = "service/";
protected static WebArchive createWebArchive(String archiveName) throws Exception {
try {
File[] files =
Maven.
configureResolver().
loadPomFromFile("target/test-classes/pom.xml").
importCompileAndRuntimeDependencies().
resolve().
withTransitivity().
asFile();
return
ShrinkWrap.
create(WebArchive.class,archiveName).
addAsLibraries(files).
addAsResource("ldp4j-server-frontend.cfg").
addAsResource("log4j.properties").
setWebXML(new File("src/main/webapp/WEB-INF/web.xml"));
} catch (Exception e) {
LOGGER.error("Could not create archive",e);
throw e;
}
}
protected final List<String> getServiceBuilds(URL contextURL) throws IOException {
Response response=
given().
accept(TEXT_TURTLE).
baseUri(contextURL.toString()).
expect().
statusCode(OK).
contentType(TEXT_TURTLE).
when().
get(SERVICE);
List<String> builds=
QueryHelper.
newInstance().
withModel(
TestingUtil.
asModel(response,contextURL,SERVICE)).
withQuery().
fromResource("queries/service_builds.sparql").
withURIRefParam("service",TestingUtil.resolve(contextURL,SERVICE)).
select(
new ResultProcessor<List<String>>() {
private List<String> builds=Lists.newArrayList();
@Override
protected void processSolution() {
this.builds.add(resource("build").getURI());
}
@Override
public List<String> getResult() {
return ImmutableList.copyOf(this.builds);
}
}
);
return builds;
}
}