Skip to content
Snippets Groups Projects
Commit b255b9be authored by Christian Wulf's avatar Christian Wulf
Browse files

Merge branch 'prework-2.0' into 'master'

Prework 2.0

Some minor things which needed to be done before 2.0

See merge request !45
parents 899636f6 08d11d9e
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net)
*
* 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 teetime.framework.pipe;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import teetime.util.classpath.ClassForNameResolver;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
public class PipeFactoryLoaderTest {
public PipeFactoryLoaderTest() {}
@Test
public void emptyConfig() throws IOException {
final List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadPipeFactoriesFromClasspath("data/empty-test.conf");
Assert.assertEquals(true, pipeFactories.isEmpty());
}
@Test
public void singleConfig() throws IOException {
final List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadPipeFactoriesFromClasspath("pipe-factories.conf");
final int lines = Files.readLines(new File("target/classes/pipe-factories.conf"), Charsets.UTF_8).size();
Assert.assertEquals(lines, pipeFactories.size());
}
@Test
public void multipleConfigs() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
final List<URL> files = new ArrayList<URL>();
final File pipeConfig = new File("target/classes/pipe-factories.conf");
final File testConfig = new File("target/test-classes/data/normal-test.conf");
files.add(testConfig.toURI().toURL());
files.add(pipeConfig.toURI().toURL());
final List<IPipeFactory> pipeFactories = PipeFactoryLoader.mergeFiles(files);
final List<String> contents = Files.readLines(pipeConfig, Charsets.UTF_8);
contents.addAll(Files.readLines(testConfig, Charsets.UTF_8));
// Check if all read factories are contained in one of the files
for (IPipeFactory iPipeFactory : pipeFactories) {
Assert.assertTrue(contents.indexOf(iPipeFactory.getClass().getCanonicalName()) != -1);
}
// Second part of the test: PipeFactoryRegistry
final PipeFactoryRegistry pipeRegistry = PipeFactoryRegistry.INSTANCE;
final ClassForNameResolver<IPipeFactory> classResolver = new ClassForNameResolver<IPipeFactory>(IPipeFactory.class);
// Look for the "normal" pipes
for (String className : Files.readLines(pipeConfig, Charsets.UTF_8)) {
final IPipeFactory pipeFactory = classResolver.classForName(className).newInstance();
final IPipeFactory returnedFactory = pipeRegistry.getPipeFactory(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(),
pipeFactory.isGrowable());
Assert.assertEquals(pipeFactory.getClass().getCanonicalName(), returnedFactory.getClass().getCanonicalName());
}
// Second "and a half" part
for (String className : Files.readLines(testConfig, Charsets.UTF_8)) {
final IPipeFactory pipeFactory = classResolver.classForName(className).newInstance();
// Still old factory
IPipeFactory returnedFactory = pipeRegistry.getPipeFactory(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(), pipeFactory.isGrowable());
Assert.assertNotEquals(pipeFactory.getClass().getCanonicalName(), returnedFactory.getClass().getCanonicalName());
// Overload factory and check for the new one
pipeRegistry.register(pipeFactory);
returnedFactory = pipeRegistry.getPipeFactory(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(), pipeFactory.isGrowable());
Assert.assertEquals(pipeFactory.getClass().getCanonicalName(), returnedFactory.getClass().getCanonicalName());
}
}
}
......@@ -32,7 +32,7 @@ import org.junit.Test;
import teetime.framework.Configuration;
import teetime.framework.Execution;
import teetime.framework.ExecutionException;
import teetime.util.Pair;
import teetime.util.ThreadThrowableContainer;
/**
* @author Nils Christian Ehmke
......@@ -117,7 +117,7 @@ public class InstanceOfFilterTest {
try {
execution.executeBlocking();
} catch (ExecutionException e) {
Collection<Pair<Thread, Throwable>> thrownExceptions = e.getThrownExceptions();
Collection<ThreadThrowableContainer> thrownExceptions = e.getThrownExceptions();
// TODO: handle exception
}
}
......
/**
* Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net)
*
* 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 teetime.util.classpath;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import teetime.util.classpath.FileSearcher;
public class FileSearcherTest {
public FileSearcherTest() {}
@Test
public void fileInClasspath() throws IOException {
final List<URL> urls = FileSearcher.loadResources("pipe-factories.conf");
Assert.assertEquals(false, urls.isEmpty());
}
@Test
public void multipleFiles() throws IOException {
final List<URL> urls = FileSearcher.loadResources("LICENSE.txt");
Assert.assertEquals(true, urls.size() > 1);
}
@Test
public void missingFile() throws IOException {
final List<URL> urls = FileSearcher.loadResources("filethatdoesnotexistinanyproject.nope");
Assert.assertEquals(true, urls.isEmpty());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment