forked from XT-i/aws-lambda-jenkins-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tested LambdaInvoker and LambdaUploader
- Loading branch information
Showing
7 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/main/java/com/xti/jenkins/plugin/awslambda/exception/AWSLambdaPluginException.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,7 @@ | ||
package com.xti.jenkins.plugin.awslambda.exception; | ||
|
||
public class AWSLambdaPluginException extends Exception { | ||
public AWSLambdaPluginException(String message) { | ||
super(message); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/xti/jenkins/plugin/awslambda/exception/LambdaInvokeException.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
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
58 changes: 58 additions & 0 deletions
58
src/test/java/com/xti/jenkins/plugin/awslambda/invoke/LambdaInvokerTest.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,58 @@ | ||
package com.xti.jenkins.plugin.awslambda.invoke; | ||
|
||
import com.xti.jenkins.plugin.awslambda.exception.LambdaInvokeException; | ||
import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; | ||
import com.xti.jenkins.plugin.awslambda.service.LambdaInvokeService; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class LambdaInvokerTest { | ||
|
||
@Mock | ||
private LambdaInvokeService service; | ||
|
||
@Mock | ||
private JenkinsLogger logger; | ||
|
||
@Test | ||
public void testInvokeSuccess() throws Exception { | ||
when(service.invokeLambdaFunction(any(InvokeConfig.class))).thenReturn("{\"key2\":\"value2\"}"); | ||
|
||
LambdaInvoker invoker = new LambdaInvoker(service, logger); | ||
|
||
InvokeConfig invokeConfig = new InvokeConfig("function", "{\"key\":\"value\"}", true, Collections.singletonList(new JsonParameter("LAMBDA_ENV_VAR", "$.key2"))); | ||
|
||
LambdaInvocationResult result = invoker.invoke(invokeConfig); | ||
|
||
assertTrue(result.isSuccess()); | ||
assertEquals("value2", result.getInjectables().get("LAMBDA_ENV_VAR")); | ||
} | ||
|
||
@Test | ||
public void testInvokeFailure() throws Exception { | ||
when(service.invokeLambdaFunction(any(InvokeConfig.class))).thenThrow(new LambdaInvokeException("Function returned error of type: Handled")); | ||
|
||
LambdaInvoker invoker = new LambdaInvoker(service, logger); | ||
|
||
InvokeConfig invokeConfig = new InvokeConfig("function", "{\"key\":\"value\"}", true, new ArrayList<JsonParameter>()); | ||
|
||
LambdaInvocationResult result = invoker.invoke(invokeConfig); | ||
|
||
assertFalse(result.isSuccess()); | ||
assertEquals(0, result.getInjectables().size()); | ||
|
||
verify(logger, times(1)).log("%nStarting lambda invocation."); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/test/java/com/xti/jenkins/plugin/awslambda/upload/LambdaUploaderTest.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,80 @@ | ||
package com.xti.jenkins.plugin.awslambda.upload; | ||
|
||
import com.xti.jenkins.plugin.awslambda.service.JenkinsLogger; | ||
import com.xti.jenkins.plugin.awslambda.service.LambdaDeployService; | ||
import com.xti.jenkins.plugin.awslambda.service.WorkSpaceZipper; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import java.io.File; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class LambdaUploaderTest { | ||
|
||
@Mock | ||
private LambdaDeployService service; | ||
|
||
@Mock | ||
private WorkSpaceZipper zipper; | ||
|
||
@Mock | ||
private JenkinsLogger logger; | ||
|
||
|
||
@Test | ||
public void testUploadSuccess() throws Exception { | ||
DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full"); | ||
File file = new File("path"); | ||
|
||
when(zipper.getZip(any(String.class))).thenReturn(file); | ||
when(service.deployLambda(any(DeployConfig.class), any(File.class), any(UpdateModeValue.class))) | ||
.thenReturn(true); | ||
|
||
LambdaUploader uploader = new LambdaUploader(service, zipper, logger); | ||
Boolean uploaded = uploader.upload(deployConfig); | ||
|
||
verify(logger, times(1)).log("%nStarting lambda deployment procedure"); | ||
verify(service, times(1)).deployLambda(deployConfig, file, UpdateModeValue.Full); | ||
assertTrue(uploaded); | ||
} | ||
|
||
@Test | ||
public void testUploadFailure() throws Exception { | ||
DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full"); | ||
File file = new File("path"); | ||
|
||
when(zipper.getZip(any(String.class))).thenReturn(file); | ||
when(service.deployLambda(any(DeployConfig.class), any(File.class), any(UpdateModeValue.class))) | ||
.thenReturn(false); | ||
|
||
LambdaUploader uploader = new LambdaUploader(service, zipper, logger); | ||
Boolean uploaded = uploader.upload(deployConfig); | ||
|
||
verify(logger, times(1)).log("%nStarting lambda deployment procedure"); | ||
verify(service, times(1)).deployLambda(deployConfig, file, UpdateModeValue.Full); | ||
assertFalse(uploaded); | ||
} | ||
|
||
@Test | ||
public void testUploadNoArtifact() throws Exception { | ||
DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full"); | ||
|
||
when(zipper.getZip(any(String.class))).thenReturn(null); | ||
when(service.deployLambda(any(DeployConfig.class), any(File.class), any(UpdateModeValue.class))) | ||
.thenReturn(true); | ||
|
||
LambdaUploader uploader = new LambdaUploader(service, zipper, logger); | ||
Boolean uploaded = uploader.upload(deployConfig); | ||
|
||
verify(logger, times(1)).log("%nStarting lambda deployment procedure"); | ||
verify(service, times(1)).deployLambda(deployConfig, null, UpdateModeValue.Full); | ||
assertTrue(uploaded); | ||
} | ||
} |