This commit is contained in:
Mohamed Karray
2018-11-29 16:01:43 +01:00
62 changed files with 1253 additions and 983 deletions

View File

@@ -45,6 +45,7 @@ public final class RepositoryTestData {
.type(type)
.contact("douglas.adams@hitchhiker.com")
.name("42Puzzle")
.namespace("hitchhiker")
.description("The 42 Puzzle")
.build();
}
@@ -59,6 +60,7 @@ public final class RepositoryTestData {
.type(type)
.contact("zaphod.beeblebrox@hitchhiker.com")
.name("happyVerticalPeopleTransporter")
.namespace("hitchhiker")
.description("Happy Vertical People Transporter")
.build();
}
@@ -72,6 +74,7 @@ public final class RepositoryTestData {
.type(type)
.contact("zaphod.beeblebrox@hitchhiker.com")
.name("HeartOfGold")
.namespace("hitchhiker")
.description(
"Heart of Gold is the first prototype ship to successfully utilise the revolutionary Infinite Improbability Drive")
.build();
@@ -87,6 +90,7 @@ public final class RepositoryTestData {
.type(type)
.contact("douglas.adams@hitchhiker.com")
.name("RestaurantAtTheEndOfTheUniverse")
.namespace("hitchhiker")
.description("The Restaurant at the End of the Universe")
.build();
}

View File

@@ -44,6 +44,7 @@ import java.io.IOException;
import java.nio.file.Path;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -62,7 +63,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
protected abstract void checkDirectory(File directory);
protected abstract RepositoryHandler createRepositoryHandler(
ConfigurationStoreFactory factory, File directory) throws IOException, RepositoryPathNotFoundException;
ConfigurationStoreFactory factory, RepositoryLocationResolver locationResolver, File directory) throws IOException, RepositoryPathNotFoundException;
@Test
public void testCreate() {
@@ -74,7 +75,15 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
InMemoryConfigurationStoreFactory storeFactory = new InMemoryConfigurationStoreFactory();
baseDirectory = new File(contextProvider.getBaseDirectory(), "repositories");
IOUtil.mkdirs(baseDirectory);
handler = createRepositoryHandler(storeFactory, baseDirectory);
locationResolver = mock(RepositoryLocationResolver.class);
when(locationResolver.getPath(anyString())).then(ic -> {
String id = ic.getArgument(0);
return baseDirectory.toPath().resolve(id);
});
handler = createRepositoryHandler(storeFactory, locationResolver, baseDirectory);
}
@Override
@@ -98,11 +107,12 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
repository = RepositoryTestData.createHeartOfGold();
File repoDirectory = new File(baseDirectory, repository.getId());
repoPath = repoDirectory.toPath();
when(repoDao.getPath(repository)).thenReturn(repoPath);
when(repoDao.getPath(repository.getId())).thenReturn(repoPath);
return new File(repoDirectory, AbstractSimpleRepositoryHandler.REPOSITORIES_NATIVE_DIRECTORY);
}
protected File baseDirectory;
protected RepositoryLocationResolver locationResolver;
private RepositoryHandler handler;
}

View File

@@ -55,6 +55,7 @@ import static org.mockito.Mockito.*;
import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
@@ -213,6 +214,10 @@ public final class MockUtil
SCMContextProvider provider = mock(SCMContextProvider.class);
when(provider.getBaseDirectory()).thenReturn(directory);
when(provider.resolve(any(Path.class))).then(ic -> {
Path p = ic.getArgument(0);
return directory.toPath().resolve(p);
});
return provider;
}