Commit ffdae21a authored by Riegel's avatar Riegel
Browse files

Open Source release of CityDoctor GUI

parent a5a82382
Pipeline #10029 failed with stage
in 8 seconds
package de.hft.stuttgart.citydoctor2.webservice.endpoints;
import java.io.IOException;
import javax.ws.rs.core.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.junit.Test;
public class BuildingEndpointTest {
@Test
public void testGetErrors() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpGet get = new HttpGet("http://localhost:8080/CityDoctorWebService/rest/buildings/10/errors");
get.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
HttpResponse response = client.execute(get);
System.out.println(TestUtils.readCompleteReponse(response));
}
}
package de.hft.stuttgart.citydoctor2.webservice.endpoints;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.Test;
public class LoginEndpointTest {
@Test
public void testLoginCorrectPassword() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
HttpPost post = new HttpPost("http://localhost:8080/CityDoctorWebService/rest/login");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("username", "Test"));
params.add(new BasicNameValuePair("password", "TestPassword"));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = client.execute(post);
assertEquals(200, response.getStatusLine().getStatusCode());
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
JSONTokener tokener = new JSONTokener(br);
JSONObject o = new JSONObject(tokener);
assertNotNull(o.getString("token"));
}
}
@Test
public void testLoginIncorrectPassword() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
HttpPost post = new HttpPost("http://localhost:8080/CityDoctorWebService/rest/login");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("username", "Test"));
params.add(new BasicNameValuePair("password", "TestIncorrectPassword"));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = client.execute(post);
assertEquals(403, response.getStatusLine().getStatusCode());
}
}
package de.hft.stuttgart.citydoctor2.webservice.endpoints;
public class LoginValues {
private String token;
private int id;
public LoginValues(String token, int id) {
super();
this.token = token;
this.id = id;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
package de.hft.stuttgart.citydoctor2.webservice.endpoints;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import javax.ws.rs.core.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.HttpClients;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.Ignore;
import org.junit.Test;
public class ModelsEndpointTest {
@Test
public void testRetrievingModels() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpGet get = new HttpGet("http://localhost:8080/CityDoctorWebService/rest/models");
get.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
HttpResponse response = client.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
JSONTokener tokener = TestUtils.tokenizeReponse(response);
JSONArray models = new JSONArray(tokener);
for (Object o : models) {
assertTrue(o instanceof JSONObject);
}
assertNotNull(models);
}
@Test
public void testUploadModel() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpPost post = new HttpPost("http://localhost:8080/CityDoctorWebService/rest/models");
post.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
File file = new File("C:\\Job\\CityGML Files\\1-stoeckach_multisurface_only.xml");
// File configFile = new File("src\\test\\resources\\testConfig.yml");
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entityBuilder.addBinaryBody("file", file);
// entityBuilder.addBinaryBody("configFile", configFile);
post.setEntity(entityBuilder.build());
HttpResponse response = client.execute(post);
int httpStatus = response.getStatusLine().getStatusCode();
assertEquals(200, httpStatus);
JSONTokener tokener = TestUtils.tokenizeReponse(response);
JSONObject model = new JSONObject(tokener);
assertNotNull(model);
assertEquals("1-stoeckach_multisurface_only.xml", model.getString("name"));
}
@Ignore
@Test
public void downloadPdfFile() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpGet get = new HttpGet(
"http://localhost:8080/CityDoctorWebService/rest/" + login.getId() + "/models/15/pdf");
get.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
HttpResponse response = client.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
Path path = Files.createTempFile(null, null);
Files.copy(response.getEntity().getContent(), path, StandardCopyOption.REPLACE_EXISTING);
assertTrue(path.toFile().exists());
}
@Ignore
@Test
public void downloadXmlFile() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpGet get = new HttpGet(
"http://localhost:8080/CityDoctorWebService/rest/" + login.getId() + "/models/15/xml");
get.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
HttpResponse response = client.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
Path path = Files.createTempFile(null, null);
Files.copy(response.getEntity().getContent(), path, StandardCopyOption.REPLACE_EXISTING);
assertTrue(path.toFile().exists());
}
@Test
public void testGetBuildings() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpGet get = new HttpGet("http://localhost:8080/CityDoctorWebService/rest/models/5/buildings?from=0");
get.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
HttpResponse response = client.execute(get);
String readCompleteReponse = TestUtils.readCompleteReponse(response);
System.out.println(readCompleteReponse);
// JSONTokener tokener = TestUtils.tokenizeReponse(response);
// JSONArray models = new JSONArray(tokener);
// for (Object o : models) {
// System.out.println(o);
// }
}
}
package de.hft.stuttgart.citydoctor2.webservice.endpoints;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.webservice.database.UserQueries;
import de.hft.stuttgart.citydoctor2.webservice.utils.HibernateUtils;
public class RegisterEndpointTest {
@Test
public void testRegisterExistingUser() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
HttpPost post = new HttpPost("http://localhost:8080/CityDoctorWebService/rest/register");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("username", "Test"));
params.add(new BasicNameValuePair("password", "TestPassword"));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = client.execute(post);
assertEquals(409, response.getStatusLine().getStatusCode());
}
@Test
public void testRegisterNewUser() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
HttpPost post = new HttpPost("http://localhost:8080/CityDoctorWebService/rest/register");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("username", "TestNotExisting"));
params.add(new BasicNameValuePair("password", "TestPassword"));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = client.execute(post);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityManager manager = HibernateUtils.createManager();
UserQueries.deleteUser(UserQueries.getUserForUsername("TestNotExisting", manager), manager);
manager.close();
}
}
package de.hft.stuttgart.citydoctor2.webservice.endpoints;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
public class TestUtils {
private TestUtils() {
// only static use
}
public static LoginValues login(HttpClient client) throws ClientProtocolException, IOException {
HttpPost post = new HttpPost("http://localhost:8080/CityDoctorWebService/rest/login");
List<NameValuePair> params = new ArrayList<>(2);
params.add(new BasicNameValuePair("username", "Test"));
params.add(new BasicNameValuePair("password", "TestPassword"));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = client.execute(post);
String text = readCompleteReponse(response);
try {
JSONTokener tokener = new JSONTokener(text);
JSONObject o = new JSONObject(tokener);
String token = o.getString("token");
int id = o.getInt("userId");
return new LoginValues(token, id);
} catch (JSONException e) {
System.out.println(text);
throw e;
}
}
public static String readCompleteReponse(HttpResponse response) throws IOException {
InputStreamReader reader = new InputStreamReader(response.getEntity().getContent());
char[] buffer = new char[1000];
int readChars = -1;
StringBuilder sb = new StringBuilder();
while ((readChars = reader.read(buffer)) != -1) {
sb.append(buffer, 0, readChars);
}
return sb.toString();
}
public static JSONTokener tokenizeReponse(HttpResponse response) throws IOException {
return new JSONTokener(readCompleteReponse(response));
}
}
package de.hft.stuttgart.citydoctor2.webservice.endpoints;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import javax.ws.rs.core.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.junit.Test;
public class ValidationEndpointTest {
@Test
public void testRetrieveXmlReport() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpGet get = new HttpGet("http://localhost:8080/CityDoctorWebService/rest/models/validations/5/xml");
get.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
HttpResponse response = client.execute(get);
File file = new File("C:/WebService/test.xml");
Files.copy(response.getEntity().getContent(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
assertTrue(file.exists());
}
@Test
public void testRetrievePdfReport() throws ClientProtocolException, IOException {
HttpClient client = HttpClients.createMinimal();
LoginValues login = TestUtils.login(client);
HttpGet get = new HttpGet("http://localhost:8080/CityDoctorWebService/rest/models/validations/5/pdf");
get.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + login.getToken());
HttpResponse response = client.execute(get);
File file = new File("C:/WebService/test.pdf");
Files.copy(response.getEntity().getContent(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
assertTrue(file.exists());
}
}
minVertexDistance: 1.0E-4
useStreaming: false
xmlValidation: false
checks:
C_GE_R_TOO_FEW_POINTS:
enabled: true
C_GE_R_NOT_CLOSED:
enabled: true
C_GE_R_DUPLICATE_POINT:
enabled: true
C_GE_R_SELF_INTERSECTION:
enabled: true
C_GE_S_MULTIPLE_CONNECTED_COMPONENTS:
enabled: true
C_GE_P_INTERIOR_DISCONNECTED:
enabled: true
C_GE_P_INTERSECTING_RINGS:
enabled: true
C_GE_P_NON_PLANAR:
enabled: false
parameters:
# one of ("distance", "angle", "both")
type: distance
distanceTolerance: 0.01
angleTolerance: 0.1
C_GE_P_HOLE_OUTSIDE:
enabled: true
C_GE_P_ORIENTATION_RINGS_SAME:
enabled: true
C_GE_P_INNER_RINGS_NESTED:
enabled: true
C_GE_S_TOO_FEW_POLYGONS:
enabled: true
C_GE_S_NOT_CLOSED:
enabled: true
C_GE_S_NON_MANIFOLD_EDGE:
enabled: true
C_GE_S_POLYGON_WRONG_ORIENTATION:
enabled: true
C_GE_S_ALL_POLYGONS_WRONG_ORIENTATION:
enabled: true
C_GE_S_NON_MANIFOLD_VERTEX:
enabled: true
C_GE_S_SELF_INTERSECTION:
enabled: true
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.hft.stuttgart</groupId>
<artifactId>CityDoctorParent</artifactId>
......@@ -217,5 +217,10 @@
<module>CityDoctorEdge</module>
<module>CityDoctorCheckResult</module>
<module>CityDoctorGUI</module>
<module>CityDoctorAutoPro</module>
<module>CityDoctorHealer</module>
<module>CityDoctorHealerGenetic</module>
<module>CityDoctorHealerGUI</module>
<module>CityDoctorWebService</module>
</modules>
</project>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment