-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...u/solven/cleanthat/lambda/step0_checkwebhook/TestCheckWebhooksLambdaFunctionAutonomy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package eu.solven.cleanthat.lambda.step0_checkwebhook; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import eu.solven.cleanthat.code_provider.github.event.IGitWebhookHandler; | ||
import eu.solven.cleanthat.code_provider.github.event.pojo.GithubWebhookEvent; | ||
import eu.solven.cleanthat.codeprovider.git.GitWebhookRelevancyResult; | ||
import eu.solven.cleanthat.lambda.step1_checkconfiguration.TestCheckConfigWebhooksLambdaFunctionAutonomy; | ||
|
||
@SpringBootTest | ||
@RunWith(SpringRunner.class) | ||
@ContextConfiguration(classes = { CheckWebhooksLambdaFunction.class, | ||
TestCheckConfigWebhooksLambdaFunctionAutonomy.CheckConfigWebhooksLambdaFunctionComplement.class }) | ||
public class TestCheckWebhooksLambdaFunctionAutonomy { | ||
|
||
@Autowired | ||
ApplicationContext appContext; | ||
|
||
@Autowired | ||
CheckWebhooksLambdaFunction function; | ||
|
||
@Test | ||
public void testAppRun() { | ||
// When | ||
{ | ||
IGitWebhookHandler gitWebhookHandler = appContext.getBean(IGitWebhookHandler.class); | ||
|
||
GitWebhookRelevancyResult value = | ||
new GitWebhookRelevancyResult(false, false, Optional.empty(), Optional.empty(), Optional.empty()); | ||
Mockito.when(gitWebhookHandler.filterWebhookEventRelevant(Mockito.any(I3rdPartyWebhookEvent.class))) | ||
.thenReturn(value); | ||
} | ||
|
||
// Then | ||
Map<String, ?> payload = ImmutableMap.<String, Object>builder().build(); | ||
function.unsafeProcessOneEvent(new GithubWebhookEvent(payload)); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...anthat/lambda/step1_checkconfiguration/TestCheckConfigWebhooksLambdaFunctionAutonomy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package eu.solven.cleanthat.lambda.step1_checkconfiguration; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import eu.solven.cleanthat.code_provider.github.event.ICodeCleanerFactory; | ||
import eu.solven.cleanthat.code_provider.github.event.IGitWebhookHandler; | ||
import eu.solven.cleanthat.code_provider.github.event.IGitWebhookHandlerFactory; | ||
import eu.solven.cleanthat.code_provider.github.event.pojo.CleanThatWebhookEvent; | ||
import eu.solven.cleanthat.code_provider.github.event.pojo.WebhookRelevancyResult; | ||
import eu.solven.cleanthat.lambda.step0_checkwebhook.IWebhookEvent; | ||
|
||
@SpringBootTest | ||
@RunWith(SpringRunner.class) | ||
@ContextConfiguration(classes = { CheckConfigWebhooksLambdaFunction.class, | ||
TestCheckConfigWebhooksLambdaFunctionAutonomy.CheckConfigWebhooksLambdaFunctionComplement.class }) | ||
public class TestCheckConfigWebhooksLambdaFunctionAutonomy { | ||
|
||
@Configuration | ||
public static class CheckConfigWebhooksLambdaFunctionComplement { | ||
|
||
@Primary | ||
@Bean | ||
public IGitWebhookHandler gitWebhookHandler() throws IOException { | ||
return Mockito.mock(IGitWebhookHandler.class); | ||
} | ||
|
||
// Override GithubWebhookHandlerFactory which will try actually connecting to GH | ||
@Primary | ||
@Bean | ||
public IGitWebhookHandlerFactory gitWebhookHandlerFactory(IGitWebhookHandler gitWebhookHandler) | ||
throws IOException { | ||
IGitWebhookHandlerFactory factory = Mockito.mock(IGitWebhookHandlerFactory.class); | ||
|
||
Mockito.when(factory.makeWithFreshAuth()).thenReturn(gitWebhookHandler); | ||
|
||
return factory; | ||
} | ||
} | ||
|
||
@Autowired | ||
ApplicationContext appContext; | ||
|
||
@Autowired | ||
CheckConfigWebhooksLambdaFunction function; | ||
|
||
@Test | ||
public void testAppRun() { | ||
// When | ||
{ | ||
IGitWebhookHandler gitWebhookHandler = appContext.getBean(IGitWebhookHandler.class); | ||
|
||
WebhookRelevancyResult value = | ||
new WebhookRelevancyResult(Optional.empty(), Optional.of("someUnitTestReason")); | ||
Mockito.when( | ||
gitWebhookHandler.filterWebhookEventTargetRelevantBranch(Mockito.any(ICodeCleanerFactory.class), | ||
Mockito.any(IWebhookEvent.class))) | ||
.thenReturn(value); | ||
} | ||
|
||
// Then | ||
Map<String, ?> payload = ImmutableMap.<String, Object>builder().build(); | ||
Map<String, Object> headers = Map.of(); | ||
function.unsafeProcessOneEvent(new CleanThatWebhookEvent(headers, payload)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...leanthat/lambda/step2_executeclean/TestExecuteCleaningWebhooksLambdaFunctionAutonomy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package eu.solven.cleanthat.lambda.step2_executeclean; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import eu.solven.cleanthat.code_provider.github.event.pojo.CleanThatWebhookEvent; | ||
import eu.solven.cleanthat.lambda.step1_checkconfiguration.TestCheckConfigWebhooksLambdaFunctionAutonomy; | ||
|
||
@SpringBootTest | ||
@RunWith(SpringRunner.class) | ||
@ContextConfiguration(classes = { ExecuteCleaningWebhooksLambdaFunction.class, | ||
TestCheckConfigWebhooksLambdaFunctionAutonomy.CheckConfigWebhooksLambdaFunctionComplement.class }) | ||
public class TestExecuteCleaningWebhooksLambdaFunctionAutonomy { | ||
|
||
@Autowired | ||
ApplicationContext appContext; | ||
|
||
@Autowired | ||
ExecuteCleaningWebhooksLambdaFunction function; | ||
|
||
@Test | ||
public void testAppRun() { | ||
// When | ||
// { | ||
// IGitWebhookHandler gitWebhookHandler = appContext.getBean(IGitWebhookHandler.class); | ||
// | ||
// WebhookRelevancyResult value = | ||
// new WebhookRelevancyResult(Optional.empty(), Optional.of("someUnitTestReason")); | ||
// Mockito.when( | ||
// gitWebhookHandler.filterWebhookEventTargetRelevantBranch(Mockito.any(ICodeCleanerFactory.class), | ||
// Mockito.any(IWebhookEvent.class))) | ||
// .thenReturn(value); | ||
// } | ||
|
||
// Then | ||
Map<String, ?> payload = ImmutableMap.<String, Object>builder().build(); | ||
Map<String, Object> headers = Map.of(); | ||
function.unsafeProcessOneEvent(new CleanThatWebhookEvent(headers, payload)); | ||
} | ||
} |