![JAR search and dependency download from the Maven repository](/logo.png)
eu.freme.bservices.testhelper.TestHelper Maven / Gradle / Ivy
/**
* Copyright © 2016 Agro-Know, Deutsches Forschungszentrum für Künstliche Intelligenz, iMinds,
* Institut für Angewandte Informatik e. V. an der Universität Leipzig,
* Istituto Superiore Mario Boella, Tilde, Vistatec, WRIPL (http://freme-project.eu)
*
* 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.
*/
package eu.freme.bservices.testhelper;
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 eu.freme.bservices.testhelper.api.IntegrationTestSetup;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import com.hp.hpl.jena.shared.AssertionFailureException;
import com.mashape.unirest.http.HttpResponse;
import eu.freme.common.conversion.rdf.RDFConstants;
import eu.freme.common.conversion.rdf.RDFConversionService;
/**
* @author Jan Nehring - [email protected]
*/
@Component
public class TestHelper implements ApplicationContextAware{
protected ApplicationContext context;
//@Autowired
//RDFConversionService rdfConversionService;
// public TestHelper(String packageConfigFileName){
// context = IntegrationTestSetup.getContext(packageConfigFileName);
// }
/**
* Returns the base url of the API given the spring application context, e.g. http://localhost:8080
* @return
*/
public String getAPIBaseUrl(){
String port = context.getEnvironment().getProperty("server.port");
if( port == null){
port = "8080";
}
return "http://localhost:" + port;
}
/**
* Return the username of the administrator user of the REST API.
*
* @return
*/
public String getAdminUsername(){
return context.getEnvironment().getProperty("admin.username");
}
/**
* Return the password of the administrator user of the REST API.
*
* @return
*/
public String getAdminPassword(){
return context.getEnvironment().getProperty("admin.password");
}
public String getResourceContent(String resourceLocation) throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(resourceLocation).getFile());
return FileUtils.readFileToString(file);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
context = applicationContext;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy