Refactor EiffelEventParserIT In preparation for tests for the EiffelEventParsingQueue. * Extract TestModule to separate file. * Introduce super class EiffelEventParsingTest with common methods for verifying event parsing. Solves: Jira GER-1715 Change-Id: I778685bf32dcad7e0a50dbc849daf2b484e7bdd4
diff --git a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserIT.java b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserIT.java index d20034b..509beba 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserIT.java
@@ -23,27 +23,12 @@ import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.config.GlobalPluginConfig; import com.google.gerrit.extensions.common.AccountInfo; -import com.google.inject.AbstractModule; -import com.google.inject.Scopes; -import com.google.inject.Singleton; -import com.googlesource.gerrit.plugins.eventseiffel.EiffelEventHub; -import com.googlesource.gerrit.plugins.eventseiffel.EiffelEventsTest; import com.googlesource.gerrit.plugins.eventseiffel.TestEventHub; import com.googlesource.gerrit.plugins.eventseiffel.TestEventStorage; -import com.googlesource.gerrit.plugins.eventseiffel.cache.EiffelEventIdCacheImpl; -import com.googlesource.gerrit.plugins.eventseiffel.config.EiffelConfig; -import com.googlesource.gerrit.plugins.eventseiffel.config.EventIdCacheConfig; -import com.googlesource.gerrit.plugins.eventseiffel.config.EventMappingConfig; import com.googlesource.gerrit.plugins.eventseiffel.eiffel.ArtifactEventKey; import com.googlesource.gerrit.plugins.eventseiffel.eiffel.CompositionDefinedEventKey; -import com.googlesource.gerrit.plugins.eventseiffel.eiffel.EventKey; import com.googlesource.gerrit.plugins.eventseiffel.eiffel.SourceChangeEventKey; -import com.googlesource.gerrit.plugins.eventseiffel.eiffel.api.EventStorage; import com.googlesource.gerrit.plugins.eventseiffel.eiffel.dto.EiffelSourceChangeSubmittedEventInfo; -import com.googlesource.gerrit.plugins.eventseiffel.mapping.EiffelEventFactory; -import com.googlesource.gerrit.plugins.eventseiffel.mapping.EiffelEventMapper; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.time.Instant; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.revwalk.RevCommit; @@ -52,10 +37,8 @@ @TestPlugin( name = "events-eiffel", - sysModule = - "com.googlesource.gerrit.plugins.eventseiffel.parsing.EiffelEventParserIT$TestModule") -public class EiffelEventParserIT extends EiffelEventsTest { - private static final Long EPOCH_MILLIS = 978307261000l; + sysModule = "com.googlesource.gerrit.plugins.eventseiffel.parsing.ParsingTestModule") +public class EiffelEventParserIT extends EiffelEventParsingTest { private EiffelEventParserImpl eventParser; @@ -239,12 +222,6 @@ return ref; } - private void setScsHandled() throws Exception { - SourceChangeEventKey scs = - SourceChangeEventKey.scsKey(project.get(), getHead(), getHeadRevision()); - markAsHandled(scs, getHead(repo(), "HEAD")); - } - @Test public void artcQueued() throws Exception { eventParser.createAndScheduleArtc(project.get(), TAG_NAME, EPOCH_MILLIS, false); @@ -297,56 +274,4 @@ private void assertNbrQueriesFor(SourceChangeEventKey key, int nbrQueries) { assertEquals(nbrQueries, TestEventStorage.INSTANCE.queriesFor(key)); } - - private String getHead() throws Exception { - return gApi.projects().name(project.get()).head(); - } - - private String getHeadRevision() throws Exception { - return getHead(repo(), "HEAD").getName(); - } - - private void assertCorrectEvent(int order, EventKey expected) { - EventKey actual = EventKey.fromEvent(TestEventHub.EVENTS.get(order)); - assertEquals(expected, actual); - } - - protected static String tagCompositionName(String projectName) { - return tagCompositionName(projectName, "localhost"); - } - - protected static String tagCompositionName(String projectName, String namespace) { - return "scmtag/git/" + namespace + "/" + URLEncoder.encode(projectName, StandardCharsets.UTF_8); - } - - protected static String tagPURL(String projectName, String tagName) { - return tagPURL(projectName, tagName, "localhost"); - } - - protected static String tagPURL(String projectName, String tagName, String namespace) { - return String.format( - TAG_PURL_TEMPLATE, - namespace, - projectName, - tagName, - String.format("ssh://%s/%s", HOST_NAME, projectName), - tagName); - } - - public static class TestModule extends AbstractModule { - @Override - protected void configure() { - bind(EventStorage.class).toProvider(TestEventStorage.Provider.class).in(Singleton.class); - bind(EventIdCacheConfig.class).toProvider(EventIdCacheConfig.Provider.class); - install(EiffelEventIdCacheImpl.module()); - bind(EiffelEventHub.class).to(TestEventHub.class); - bind(EventMappingConfig.class).toProvider(EventMappingConfig.Provider.class); - bind(EiffelEventMapper.class); - bind(EiffelEventParser.class).to(EiffelEventParserImpl.class); - bind(EiffelConfig.class).toProvider(EiffelConfig.Provider.class).in(Scopes.SINGLETON); - bind(EiffelEventFactory.class) - .toProvider(EiffelEventFactory.Provider.class) - .in(Scopes.SINGLETON); - } - } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParsingTest.java b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParsingTest.java new file mode 100644 index 0000000..7d8c926 --- /dev/null +++ b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParsingTest.java
@@ -0,0 +1,57 @@ +package com.googlesource.gerrit.plugins.eventseiffel.parsing; + +import static org.junit.Assert.assertEquals; + +import com.googlesource.gerrit.plugins.eventseiffel.EiffelEventsTest; +import com.googlesource.gerrit.plugins.eventseiffel.TestEventHub; +import com.googlesource.gerrit.plugins.eventseiffel.eiffel.EventKey; +import com.googlesource.gerrit.plugins.eventseiffel.eiffel.SourceChangeEventKey; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import org.junit.Ignore; + +@Ignore +public class EiffelEventParsingTest extends EiffelEventsTest { + protected static final Long EPOCH_MILLIS = 978307261000l; + + protected static String tagCompositionName(String projectName) { + return tagCompositionName(projectName, "localhost"); + } + + protected static String tagCompositionName(String projectName, String namespace) { + return "scmtag/git/" + namespace + "/" + URLEncoder.encode(projectName, StandardCharsets.UTF_8); + } + + protected static String tagPURL(String projectName, String tagName) { + return tagPURL(projectName, tagName, "localhost"); + } + + protected static String tagPURL(String projectName, String tagName, String namespace) { + return String.format( + TAG_PURL_TEMPLATE, + namespace, + projectName, + tagName, + String.format("ssh://%s/%s", HOST_NAME, projectName), + tagName); + } + + protected void assertCorrectEvent(int order, EventKey expected) { + EventKey actual = EventKey.fromEvent(TestEventHub.EVENTS.get(order)); + assertEquals(expected, actual); + } + + protected void setScsHandled() throws Exception { + SourceChangeEventKey scs = + SourceChangeEventKey.scsKey(project.get(), getHead(), getHeadRevision()); + markAsHandled(scs, getHead(repo(), "HEAD")); + } + + protected String getHead() throws Exception { + return gApi.projects().name(project.get()).head(); + } + + protected String getHeadRevision() throws Exception { + return getHead(repo(), "HEAD").getName(); + } +}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/ParsingTestModule.java b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/ParsingTestModule.java new file mode 100644 index 0000000..f3fe7e5 --- /dev/null +++ b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/ParsingTestModule.java
@@ -0,0 +1,34 @@ +package com.googlesource.gerrit.plugins.eventseiffel.parsing; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; +import com.google.inject.Singleton; +import com.googlesource.gerrit.plugins.eventseiffel.EiffelEventHub; +import com.googlesource.gerrit.plugins.eventseiffel.TestEventHub; +import com.googlesource.gerrit.plugins.eventseiffel.TestEventStorage; +import com.googlesource.gerrit.plugins.eventseiffel.cache.EiffelEventIdCacheImpl; +import com.googlesource.gerrit.plugins.eventseiffel.config.EiffelConfig; +import com.googlesource.gerrit.plugins.eventseiffel.config.EventIdCacheConfig; +import com.googlesource.gerrit.plugins.eventseiffel.config.EventMappingConfig; +import com.googlesource.gerrit.plugins.eventseiffel.eiffel.api.EventStorage; +import com.googlesource.gerrit.plugins.eventseiffel.mapping.EiffelEventFactory; +import com.googlesource.gerrit.plugins.eventseiffel.mapping.EiffelEventMapper; +import org.junit.Ignore; + +@Ignore +public class ParsingTestModule extends AbstractModule { + @Override + protected void configure() { + bind(EventStorage.class).toProvider(TestEventStorage.Provider.class).in(Singleton.class); + bind(EventIdCacheConfig.class).toProvider(EventIdCacheConfig.Provider.class); + install(EiffelEventIdCacheImpl.module()); + bind(EiffelEventHub.class).to(TestEventHub.class); + bind(EventMappingConfig.class).toProvider(EventMappingConfig.Provider.class); + bind(EiffelEventMapper.class); + bind(EiffelEventParser.class).to(EiffelEventParserImpl.class); + bind(EiffelConfig.class).toProvider(EiffelConfig.Provider.class).in(Scopes.SINGLETON); + bind(EiffelEventFactory.class) + .toProvider(EiffelEventFactory.Provider.class) + .in(Scopes.SINGLETON); + } +}