target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void testSplitLinesCRLF() { final String[] lines = TextUtils.splitLines("foo \r\n bar \r\n baz"); assertEquals(3, lines.length); assertEquals("foo ", lines[0]); assertEquals(" bar ", lines[1]); assertEquals(" baz", lines[2]); } | public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } |
@Test public void testSplitLinesMixtureCRLF() { final String[] lines = TextUtils.splitLines("foo \n bar \r\n baz"); assertEquals(3, lines.length); assertEquals("foo ", lines[0]); assertEquals(" bar ", lines[1]); assertEquals(" baz", lines[2]); } | public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } |
@Test public void testSplitLinesNull() { try { TextUtils.splitLines(null); fail("Should throw NPE"); } catch (NullPointerException ex) { } } | public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } |
@Test public void testSplitLinesEmpty() { assertEquals(1, TextUtils.splitLines("").length); assertEquals(1, TextUtils.splitLines(" ").length); } | public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } | TextUtils { public static String[] splitLines(String text) { Preconditions.checkNotNull(text, "The parameter 'text' cannot be null"); return text.split("\\r?\\n"); } private TextUtils(); static String applyColorToText(String text, Color colorCode); static String yellow(String message); static String green(String message); static String blue(String message); static String red(String message); static String[] splitLines(String text); } |
@Test public void testFromJson() { final String testFailure = "{{{{{{{{{{{"; Object obj = null; try { obj = JsonUtils.fromJson(testString, Map.class); } catch (final Exception e) { fail("Fail to parse a json to java.util.Map."); } assertTrue(((Map<String, Object>) obj).containsKey("id")); assertTrue(((Map<String, Object>) obj).get("id") instanceof Number); try { obj = JsonUtils.fromJson(testString, ObjectForJson.class); } catch (final Exception e) { fail("Fail to parse a json to java.util.Map."); } final ObjectForJson objForJson = (ObjectForJson) obj; assertEquals(1, objForJson.id); assertEquals("hello", objForJson.title); assertEquals(1, objForJson.children.length); assertEquals(2, objForJson.children[0].id); try { obj = JsonUtils.fromJson(testFailure, Map.class); fail("Should fail for invalid json."); } catch (final Exception e) { } } | public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { return GSON.fromJson(json, classOfT); } | JsonUtils { public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { return GSON.fromJson(json, classOfT); } } | JsonUtils { public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { return GSON.fromJson(json, classOfT); } private JsonUtils(); } | JsonUtils { public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { return GSON.fromJson(json, classOfT); } private JsonUtils(); static T fromJson(String json, Class<T> classOfT); static String toJson(Object src); } | JsonUtils { public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { return GSON.fromJson(json, classOfT); } private JsonUtils(); static T fromJson(String json, Class<T> classOfT); static String toJson(Object src); } |
@Test public void testToJson() { final ObjectForJson objForJson = JsonUtils.fromJson(testString, ObjectForJson.class); final String json = JsonUtils.toJson(objForJson); assertEquals(testString, json); } | public static String toJson(Object src) { return GSON.toJson(src); } | JsonUtils { public static String toJson(Object src) { return GSON.toJson(src); } } | JsonUtils { public static String toJson(Object src) { return GSON.toJson(src); } private JsonUtils(); } | JsonUtils { public static String toJson(Object src) { return GSON.toJson(src); } private JsonUtils(); static T fromJson(String json, Class<T> classOfT); static String toJson(Object src); } | JsonUtils { public static String toJson(Object src) { return GSON.toJson(src); } private JsonUtils(); static T fromJson(String json, Class<T> classOfT); static String toJson(Object src); } |
@Test public void doExecute() throws Exception { final ArtifactHandler handler = mock(ArtifactHandler.class); final FunctionRuntimeHandler runtimeHandler = mock(FunctionRuntimeHandler.class); final FunctionApp app = mock(FunctionApp.class); doReturn(app).when(mojoSpy).getFunctionApp(); doReturn(app).when(mojoSpy).updateFunctionApp(app, runtimeHandler); doReturn(handler).when(mojoSpy).getArtifactHandler(); doReturn(runtimeHandler).when(mojoSpy).getFunctionRuntimeHandler(); doCallRealMethod().when(mojoSpy).createOrUpdateResource(); final DeployTarget deployTarget = new DeployTarget(app, DeployTargetType.FUNCTION); doNothing().when(mojoSpy).listHTTPTriggerUrls(); doNothing().when(mojoSpy).checkArtifactCompileVersion(); doNothing().when(mojoSpy).parseConfiguration(); doReturn(null).when(mojoSpy).getResourcePortalUrl(any()); mojoSpy.doExecute(); verify(mojoSpy, times(1)).createOrUpdateResource(); verify(mojoSpy, times(1)).doExecute(); verify(mojoSpy, times(1)).updateFunctionApp(any(FunctionApp.class), any()); verify(handler, times(1)).publish(refEq(deployTarget)); verifyNoMoreInteractions(handler); } | @Override protected void doExecute() throws AzureExecutionException { try { parseConfiguration(); checkArtifactCompileVersion(); final WebAppBase target = createOrUpdateResource(); if (target == null) { throw new AzureExecutionException( String.format("Failed to get the deploy target with name: %s", getAppName())); } final DeployTarget deployTarget = new DeployTarget(target, DeployTargetType.FUNCTION); Log.info(DEPLOY_START); getArtifactHandler().publish(deployTarget); Log.info(String.format(DEPLOY_FINISH, getResourcePortalUrl(target))); if (!isDeployToSlot()) { listHTTPTriggerUrls(); } } catch (AzureAuthFailureException e) { throw new AzureExecutionException("Cannot auth to azure", e); } } | DeployMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { parseConfiguration(); checkArtifactCompileVersion(); final WebAppBase target = createOrUpdateResource(); if (target == null) { throw new AzureExecutionException( String.format("Failed to get the deploy target with name: %s", getAppName())); } final DeployTarget deployTarget = new DeployTarget(target, DeployTargetType.FUNCTION); Log.info(DEPLOY_START); getArtifactHandler().publish(deployTarget); Log.info(String.format(DEPLOY_FINISH, getResourcePortalUrl(target))); if (!isDeployToSlot()) { listHTTPTriggerUrls(); } } catch (AzureAuthFailureException e) { throw new AzureExecutionException("Cannot auth to azure", e); } } } | DeployMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { parseConfiguration(); checkArtifactCompileVersion(); final WebAppBase target = createOrUpdateResource(); if (target == null) { throw new AzureExecutionException( String.format("Failed to get the deploy target with name: %s", getAppName())); } final DeployTarget deployTarget = new DeployTarget(target, DeployTargetType.FUNCTION); Log.info(DEPLOY_START); getArtifactHandler().publish(deployTarget); Log.info(String.format(DEPLOY_FINISH, getResourcePortalUrl(target))); if (!isDeployToSlot()) { listHTTPTriggerUrls(); } } catch (AzureAuthFailureException e) { throw new AzureExecutionException("Cannot auth to azure", e); } } } | DeployMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { parseConfiguration(); checkArtifactCompileVersion(); final WebAppBase target = createOrUpdateResource(); if (target == null) { throw new AzureExecutionException( String.format("Failed to get the deploy target with name: %s", getAppName())); } final DeployTarget deployTarget = new DeployTarget(target, DeployTargetType.FUNCTION); Log.info(DEPLOY_START); getArtifactHandler().publish(deployTarget); Log.info(String.format(DEPLOY_FINISH, getResourcePortalUrl(target))); if (!isDeployToSlot()) { listHTTPTriggerUrls(); } } catch (AzureAuthFailureException e) { throw new AzureExecutionException("Cannot auth to azure", e); } } @Override DeploymentType getDeploymentType(); } | DeployMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { try { parseConfiguration(); checkArtifactCompileVersion(); final WebAppBase target = createOrUpdateResource(); if (target == null) { throw new AzureExecutionException( String.format("Failed to get the deploy target with name: %s", getAppName())); } final DeployTarget deployTarget = new DeployTarget(target, DeployTargetType.FUNCTION); Log.info(DEPLOY_START); getArtifactHandler().publish(deployTarget); Log.info(String.format(DEPLOY_FINISH, getResourcePortalUrl(target))); if (!isDeployToSlot()) { listHTTPTriggerUrls(); } } catch (AzureAuthFailureException e) { throw new AzureExecutionException("Cannot auth to azure", e); } } @Override DeploymentType getDeploymentType(); } |
@Test public void testXmlIndent() { final String[] lines = TextUtils.splitLines("<foo> \n <bar> \n \t<test></test></bar> \r\n </foo>"); assertEquals(" ", IndentUtil.calcXmlIndent(lines, 1, 2)); assertEquals(" \t", IndentUtil.calcXmlIndent(lines, 2, 12)); } | public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } private IndentUtil(); } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } private IndentUtil(); static String calcXmlIndent(String[] lines, int row, int column); } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } private IndentUtil(); static String calcXmlIndent(String[] lines, int row, int column); } |
@Test public void testXmlIndentBadArgument() { final String[] lines = TextUtils.splitLines("<foo> \n <bar> \n \t<test></test></bar> \r\n </foo>"); try { IndentUtil.calcXmlIndent(lines, 100, 1); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } try { IndentUtil.calcXmlIndent(lines, -1, 1); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } try { IndentUtil.calcXmlIndent(lines, 0, -1); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } try { IndentUtil.calcXmlIndent(lines, 0, 1000); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } try { IndentUtil.calcXmlIndent(null, 1, 1000); fail("Should throw NPE"); } catch (NullPointerException ex) { } try { IndentUtil.calcXmlIndent(new String[] { null }, 0, 1000); fail("Should throw IAE"); } catch (IllegalArgumentException ex) { } } | public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } private IndentUtil(); } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } private IndentUtil(); static String calcXmlIndent(String[] lines, int row, int column); } | IndentUtil { public static String calcXmlIndent(String[] lines, int row, int column) { Preconditions.checkNotNull(lines, "The parameter 'lines' cannot be null"); Preconditions.checkArgument(lines.length > row && row >= 0, "The parameter 'row' overflows."); final String line = lines[row]; Preconditions.checkArgument(line != null, "Encounter null on row: " + row); Preconditions.checkArgument(line.length() >= column && column >= 0, "The parameter 'column' overflows"); final StringBuilder buffer = new StringBuilder(); final int pos = line.lastIndexOf('<', column) - 1; for (int i = 0; i <= pos; i++) { if (line.charAt(i) == '\t') { buffer.append('\t'); } else { buffer.append(' '); } } return buffer.toString(); } private IndentUtil(); static String calcXmlIndent(String[] lines, int row, int column); } |
@Test public void findFunctions() throws Exception { final AnnotationHandler handler = getAnnotationHandler(); final Set<Method> functions = handler.findFunctions(Arrays.asList(getClassUrl())); assertEquals(13, functions.size()); final List<String> methodNames = functions.stream().map(f -> f.getName()).collect(Collectors.toList()); assertTrue(methodNames.contains(HTTP_TRIGGER_METHOD)); assertTrue(methodNames.contains(QUEUE_TRIGGER_METHOD)); assertTrue(methodNames.contains(TIMER_TRIGGER_METHOD)); assertTrue(methodNames.contains(MULTI_OUTPUT_METHOD)); assertTrue(methodNames.contains(BLOB_TRIGGER_METHOD)); assertTrue(methodNames.contains(EVENTHUB_TRIGGER_METHOD)); assertTrue(methodNames.contains(SERVICE_BUS_QUEUE_TRIGGER_METHOD)); assertTrue(methodNames.contains(SERVICE_BUS_TOPIC_TRIGGER_METHOD)); assertTrue(methodNames.contains(COSMOSDB_TRIGGER_METHOD)); assertTrue(methodNames.contains(EVENTGRID_TRIGGER_METHOD)); assertTrue(methodNames.contains(CUSTOM_BINDING_METHOD)); assertTrue(methodNames.contains(EXTENDING_CUSTOM_BINDING_METHOD)); assertTrue(methodNames.contains(EXTENDING_CUSTOM_BINDING_WITHOUT_NAME_METHOD)); } | @Override public Set<Method> findFunctions(final List<URL> urls) { return new Reflections( new ConfigurationBuilder() .addUrls(urls) .setScanners(new MethodAnnotationsScanner()) .addClassLoader(getClassLoader(urls))) .getMethodsAnnotatedWith(FunctionName.class); } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Set<Method> findFunctions(final List<URL> urls) { return new Reflections( new ConfigurationBuilder() .addUrls(urls) .setScanners(new MethodAnnotationsScanner()) .addClassLoader(getClassLoader(urls))) .getMethodsAnnotatedWith(FunctionName.class); } } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Set<Method> findFunctions(final List<URL> urls) { return new Reflections( new ConfigurationBuilder() .addUrls(urls) .setScanners(new MethodAnnotationsScanner()) .addClassLoader(getClassLoader(urls))) .getMethodsAnnotatedWith(FunctionName.class); } } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Set<Method> findFunctions(final List<URL> urls) { return new Reflections( new ConfigurationBuilder() .addUrls(urls) .setScanners(new MethodAnnotationsScanner()) .addClassLoader(getClassLoader(urls))) .getMethodsAnnotatedWith(FunctionName.class); } @Override Set<Method> findFunctions(final List<URL> urls); @Override Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods); @Override FunctionConfiguration generateConfiguration(final Method method); } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Set<Method> findFunctions(final List<URL> urls) { return new Reflections( new ConfigurationBuilder() .addUrls(urls) .setScanners(new MethodAnnotationsScanner()) .addClassLoader(getClassLoader(urls))) .getMethodsAnnotatedWith(FunctionName.class); } @Override Set<Method> findFunctions(final List<URL> urls); @Override Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods); @Override FunctionConfiguration generateConfiguration(final Method method); } |
@Test public void generateConfigurations() throws Exception { final AnnotationHandler handler = getAnnotationHandler(); final Set<Method> functions = handler.findFunctions(Arrays.asList(getClassUrl())); final Map<String, FunctionConfiguration> configMap = handler.generateConfigurations(functions); configMap.values().forEach(config -> config.validate()); assertEquals(13, configMap.size()); verifyFunctionConfiguration(configMap, HTTP_TRIGGER_FUNCTION, HTTP_TRIGGER_METHOD, 2); verifyFunctionConfiguration(configMap, QUEUE_TRIGGER_FUNCTION, QUEUE_TRIGGER_METHOD, 2); verifyFunctionConfiguration(configMap, TIMER_TRIGGER_FUNCTION, TIMER_TRIGGER_METHOD, 5); verifyFunctionConfiguration(configMap, MULTI_OUTPUT_FUNCTION, MULTI_OUTPUT_METHOD, 3); verifyFunctionConfiguration(configMap, BLOB_TRIGGER_FUNCTION, BLOB_TRIGGER_METHOD, 5); verifyFunctionConfiguration(configMap, EVENTHUB_TRIGGER_FUNCTION, EVENTHUB_TRIGGER_METHOD, 2); verifyFunctionConfiguration(configMap, SERVICE_BUS_QUEUE_TRIGGER_FUNCTION, SERVICE_BUS_QUEUE_TRIGGER_METHOD, 2); verifyFunctionConfiguration(configMap, SERVICE_BUS_TOPIC_TRIGGER_FUNCTION, SERVICE_BUS_TOPIC_TRIGGER_METHOD, 2); verifyFunctionConfiguration(configMap, COSMOSDB_TRIGGER_FUNCTION, COSMOSDB_TRIGGER_METHOD, 2); verifyFunctionConfiguration(configMap, EVENTGRID_TRIGGER_FUNCTION, EVENTGRID_TRIGGER_METHOD, 1); verifyFunctionConfiguration(configMap, CUSTOM_BINDING_FUNCTION, CUSTOM_BINDING_METHOD, 1); verifyFunctionConfiguration(configMap, EXTENDING_CUSTOM_BINDING_FUNCTION, EXTENDING_CUSTOM_BINDING_METHOD, 1); verifyFunctionBinding(configMap.get(COSMOSDB_TRIGGER_FUNCTION).getBindings().stream() .filter(baseBinding -> baseBinding.getName().equals("cosmos")).findFirst().get(), COSMOSDB_TRIGGER_REQUIRED_ATTRIBUTES, true); verifyFunctionBinding(configMap.get(COSMOSDB_TRIGGER_FUNCTION).getBindings().stream() .filter(baseBinding -> baseBinding.getName().equals("itemOut")).findFirst().get(), COSMOSDB_OUTPUT_REQUIRED_ATTRIBUTES, false); verifyFunctionBinding(configMap.get(EVENTHUB_TRIGGER_FUNCTION).getBindings().stream() .filter(baseBinding -> baseBinding.getName().equals("messages")).findFirst().get(), EVENTHUB_TRIGGER_REQUIRED_ATTRIBUTES, true); final Binding customBinding = configMap.get(CUSTOM_BINDING_FUNCTION).getBindings().get(0); verifyFunctionBinding(customBinding, CUSTOM_BINDING_REQUIRED_ATTRIBUTES, true); assertEquals(customBinding.getName(), "input"); assertEquals(customBinding.getDirection(), "in"); assertEquals(customBinding.getType(), "customBinding"); final Binding extendingCustomBinding = configMap.get(EXTENDING_CUSTOM_BINDING_FUNCTION).getBindings().get(0); verifyFunctionBinding(extendingCustomBinding, EXTENDING_CUSTOM_BINDING_REQUIRED_ATTRIBUTES, true); assertEquals(extendingCustomBinding.getName(), "extendingCustomBinding"); assertEquals(extendingCustomBinding.getDirection(), "in"); assertEquals(extendingCustomBinding.getType(), "customBinding"); final Binding extendingCustomBindingWithoutName = configMap.get(EXTENDING_CUSTOM_BINDING_WITHOUT_NAME_FUNCTION) .getBindings().get(0); verifyFunctionBinding(extendingCustomBindingWithoutName, EXTENDING_CUSTOM_BINDING_REQUIRED_ATTRIBUTES, true); assertEquals(extendingCustomBindingWithoutName.getName(), "message"); assertEquals(extendingCustomBindingWithoutName.getDirection(), "in"); assertEquals(extendingCustomBindingWithoutName.getType(), "customBinding"); } | @Override public Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods) throws AzureExecutionException { final Map<String, FunctionConfiguration> configMap = new HashMap<>(); for (final Method method : methods) { final FunctionName functionAnnotation = method.getAnnotation(FunctionName.class); final String functionName = functionAnnotation.value(); validateFunctionName(configMap.keySet(), functionName); Log.debug("Starting processing function : " + functionName); configMap.put(functionName, generateConfiguration(method)); } return configMap; } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods) throws AzureExecutionException { final Map<String, FunctionConfiguration> configMap = new HashMap<>(); for (final Method method : methods) { final FunctionName functionAnnotation = method.getAnnotation(FunctionName.class); final String functionName = functionAnnotation.value(); validateFunctionName(configMap.keySet(), functionName); Log.debug("Starting processing function : " + functionName); configMap.put(functionName, generateConfiguration(method)); } return configMap; } } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods) throws AzureExecutionException { final Map<String, FunctionConfiguration> configMap = new HashMap<>(); for (final Method method : methods) { final FunctionName functionAnnotation = method.getAnnotation(FunctionName.class); final String functionName = functionAnnotation.value(); validateFunctionName(configMap.keySet(), functionName); Log.debug("Starting processing function : " + functionName); configMap.put(functionName, generateConfiguration(method)); } return configMap; } } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods) throws AzureExecutionException { final Map<String, FunctionConfiguration> configMap = new HashMap<>(); for (final Method method : methods) { final FunctionName functionAnnotation = method.getAnnotation(FunctionName.class); final String functionName = functionAnnotation.value(); validateFunctionName(configMap.keySet(), functionName); Log.debug("Starting processing function : " + functionName); configMap.put(functionName, generateConfiguration(method)); } return configMap; } @Override Set<Method> findFunctions(final List<URL> urls); @Override Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods); @Override FunctionConfiguration generateConfiguration(final Method method); } | AnnotationHandlerImpl implements AnnotationHandler { @Override public Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods) throws AzureExecutionException { final Map<String, FunctionConfiguration> configMap = new HashMap<>(); for (final Method method : methods) { final FunctionName functionAnnotation = method.getAnnotation(FunctionName.class); final String functionName = functionAnnotation.value(); validateFunctionName(configMap.keySet(), functionName); Log.debug("Starting processing function : " + functionName); configMap.put(functionName, generateConfiguration(method)); } return configMap; } @Override Set<Method> findFunctions(final List<URL> urls); @Override Map<String, FunctionConfiguration> generateConfigurations(final Set<Method> methods); @Override FunctionConfiguration generateConfiguration(final Method method); } |
@Test public void publish() throws Exception { final DeployTarget deployTarget = mock(DeployTarget.class); final Map mapSettings = mock(Map.class); final File file = mock(File.class); final AppSetting storageSetting = mock(AppSetting.class); mapSettings.put(INTERNAL_STORAGE_KEY, storageSetting); doReturn(mapSettings).when(deployTarget).getAppSettings(); doReturn(storageSetting).when(mapSettings).get(anyString()); buildHandler(); PowerMockito.mockStatic(FunctionArtifactHelper.class); when(FunctionArtifactHelper.getCloudStorageAccount(any())).thenReturn(null); doReturn("").when(handlerSpy).uploadPackageToAzureStorage(file, null, ""); doReturn("").when(handlerSpy).getBlobName(); doReturn(mapSettings).when(deployTarget).getAppSettings(); doNothing().when(handlerSpy).deployWithPackageUri(eq(deployTarget), eq(""), any(Runnable.class)); doReturn(file).when(handlerSpy).createZipPackage(); handlerSpy.publish(deployTarget); verify(handlerSpy, times(1)).publish(deployTarget); verify(handlerSpy, times(1)).createZipPackage(); verify(handlerSpy, times(1)).getBlobName(); verify(handlerSpy, times(1)).uploadPackageToAzureStorage(file, null, ""); verify(handlerSpy, times(1)).deployWithPackageUri(eq(deployTarget), eq(""), any(Runnable.class)); verifyNoMoreInteractions(handlerSpy); } | @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File zipPackage = createZipPackage(); final CloudStorageAccount storageAccount = FunctionArtifactHelper.getCloudStorageAccount(target); final String blobName = getBlobName(); final String packageUri = uploadPackageToAzureStorage(zipPackage, storageAccount, blobName); deployWithPackageUri(target, packageUri, () -> deletePackageFromAzureStorage(storageAccount, blobName)); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File zipPackage = createZipPackage(); final CloudStorageAccount storageAccount = FunctionArtifactHelper.getCloudStorageAccount(target); final String blobName = getBlobName(); final String packageUri = uploadPackageToAzureStorage(zipPackage, storageAccount, blobName); deployWithPackageUri(target, packageUri, () -> deletePackageFromAzureStorage(storageAccount, blobName)); } } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File zipPackage = createZipPackage(); final CloudStorageAccount storageAccount = FunctionArtifactHelper.getCloudStorageAccount(target); final String blobName = getBlobName(); final String packageUri = uploadPackageToAzureStorage(zipPackage, storageAccount, blobName); deployWithPackageUri(target, packageUri, () -> deletePackageFromAzureStorage(storageAccount, blobName)); } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File zipPackage = createZipPackage(); final CloudStorageAccount storageAccount = FunctionArtifactHelper.getCloudStorageAccount(target); final String blobName = getBlobName(); final String packageUri = uploadPackageToAzureStorage(zipPackage, storageAccount, blobName); deployWithPackageUri(target, packageUri, () -> deletePackageFromAzureStorage(storageAccount, blobName)); } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File zipPackage = createZipPackage(); final CloudStorageAccount storageAccount = FunctionArtifactHelper.getCloudStorageAccount(target); final String blobName = getBlobName(); final String packageUri = uploadPackageToAzureStorage(zipPackage, storageAccount, blobName); deployWithPackageUri(target, packageUri, () -> deletePackageFromAzureStorage(storageAccount, blobName)); } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); static final String DEPLOYMENT_PACKAGE_CONTAINER; static final String CREATE_ZIP_START; static final String CREATE_ZIP_DONE; static final String UPLOAD_PACKAGE_START; static final String UPLOAD_PACKAGE_DONE; static final String DEPLOY_PACKAGE_START; static final String DEPLOY_PACKAGE_DONE; static final String DELETE_PACKAGE_START; static final String DELETE_PACKAGE_DONE; static final String DELETE_PACKAGE_FAIL; } |
@Test public void createZipPackage() throws Exception { buildHandler(); final File zipPackage = handlerSpy.createZipPackage(); assertTrue(zipPackage.exists()); } | protected File createZipPackage() throws AzureExecutionException { Log.prompt(""); Log.prompt(CREATE_ZIP_START); final File zipPackage = FunctionArtifactHelper.createFunctionArtifact(stagingDirectoryPath); Log.prompt(CREATE_ZIP_DONE + stagingDirectoryPath.concat(Constants.ZIP_EXT)); return zipPackage; } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected File createZipPackage() throws AzureExecutionException { Log.prompt(""); Log.prompt(CREATE_ZIP_START); final File zipPackage = FunctionArtifactHelper.createFunctionArtifact(stagingDirectoryPath); Log.prompt(CREATE_ZIP_DONE + stagingDirectoryPath.concat(Constants.ZIP_EXT)); return zipPackage; } } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected File createZipPackage() throws AzureExecutionException { Log.prompt(""); Log.prompt(CREATE_ZIP_START); final File zipPackage = FunctionArtifactHelper.createFunctionArtifact(stagingDirectoryPath); Log.prompt(CREATE_ZIP_DONE + stagingDirectoryPath.concat(Constants.ZIP_EXT)); return zipPackage; } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected File createZipPackage() throws AzureExecutionException { Log.prompt(""); Log.prompt(CREATE_ZIP_START); final File zipPackage = FunctionArtifactHelper.createFunctionArtifact(stagingDirectoryPath); Log.prompt(CREATE_ZIP_DONE + stagingDirectoryPath.concat(Constants.ZIP_EXT)); return zipPackage; } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected File createZipPackage() throws AzureExecutionException { Log.prompt(""); Log.prompt(CREATE_ZIP_START); final File zipPackage = FunctionArtifactHelper.createFunctionArtifact(stagingDirectoryPath); Log.prompt(CREATE_ZIP_DONE + stagingDirectoryPath.concat(Constants.ZIP_EXT)); return zipPackage; } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); static final String DEPLOYMENT_PACKAGE_CONTAINER; static final String CREATE_ZIP_START; static final String CREATE_ZIP_DONE; static final String UPLOAD_PACKAGE_START; static final String UPLOAD_PACKAGE_DONE; static final String DEPLOY_PACKAGE_START; static final String DEPLOY_PACKAGE_DONE; static final String DELETE_PACKAGE_START; static final String DELETE_PACKAGE_DONE; static final String DELETE_PACKAGE_FAIL; } |
@Test public void uploadPackageToAzureStorage() throws Exception { final CloudStorageAccount storageAccount = mock(CloudStorageAccount.class); final CloudBlobClient blobClient = mock(CloudBlobClient.class); doReturn(blobClient).when(storageAccount).createCloudBlobClient(); final CloudBlobContainer blobContainer = mock(CloudBlobContainer.class); doReturn(blobContainer).when(blobClient).getContainerReference(anyString()); doReturn(true).when(blobContainer) .createIfNotExists(any(BlobContainerPublicAccessType.class), isNull(), isNull()); final CloudBlockBlob blob = mock(CloudBlockBlob.class); doReturn(blob).when(blobContainer).getBlockBlobReference(anyString()); doNothing().when(blob).upload(any(FileInputStream.class), anyLong()); doReturn(new URI("http: final File file = new File("pom.xml"); buildHandler(); final String packageUri = handler.uploadPackageToAzureStorage(file, storageAccount, "blob"); assertSame("http: } | protected String uploadPackageToAzureStorage(final File zipPackage, final CloudStorageAccount storageAccount, final String blobName) throws AzureExecutionException { Log.prompt(UPLOAD_PACKAGE_START); final CloudBlockBlob blob = AzureStorageHelper.uploadFileAsBlob(zipPackage, storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); final String packageUri = blob.getUri().toString(); Log.prompt(UPLOAD_PACKAGE_DONE + packageUri); return packageUri; } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected String uploadPackageToAzureStorage(final File zipPackage, final CloudStorageAccount storageAccount, final String blobName) throws AzureExecutionException { Log.prompt(UPLOAD_PACKAGE_START); final CloudBlockBlob blob = AzureStorageHelper.uploadFileAsBlob(zipPackage, storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); final String packageUri = blob.getUri().toString(); Log.prompt(UPLOAD_PACKAGE_DONE + packageUri); return packageUri; } } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected String uploadPackageToAzureStorage(final File zipPackage, final CloudStorageAccount storageAccount, final String blobName) throws AzureExecutionException { Log.prompt(UPLOAD_PACKAGE_START); final CloudBlockBlob blob = AzureStorageHelper.uploadFileAsBlob(zipPackage, storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); final String packageUri = blob.getUri().toString(); Log.prompt(UPLOAD_PACKAGE_DONE + packageUri); return packageUri; } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected String uploadPackageToAzureStorage(final File zipPackage, final CloudStorageAccount storageAccount, final String blobName) throws AzureExecutionException { Log.prompt(UPLOAD_PACKAGE_START); final CloudBlockBlob blob = AzureStorageHelper.uploadFileAsBlob(zipPackage, storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); final String packageUri = blob.getUri().toString(); Log.prompt(UPLOAD_PACKAGE_DONE + packageUri); return packageUri; } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected String uploadPackageToAzureStorage(final File zipPackage, final CloudStorageAccount storageAccount, final String blobName) throws AzureExecutionException { Log.prompt(UPLOAD_PACKAGE_START); final CloudBlockBlob blob = AzureStorageHelper.uploadFileAsBlob(zipPackage, storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); final String packageUri = blob.getUri().toString(); Log.prompt(UPLOAD_PACKAGE_DONE + packageUri); return packageUri; } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); static final String DEPLOYMENT_PACKAGE_CONTAINER; static final String CREATE_ZIP_START; static final String CREATE_ZIP_DONE; static final String UPLOAD_PACKAGE_START; static final String UPLOAD_PACKAGE_DONE; static final String DEPLOY_PACKAGE_START; static final String DEPLOY_PACKAGE_DONE; static final String DELETE_PACKAGE_START; static final String DELETE_PACKAGE_DONE; static final String DELETE_PACKAGE_FAIL; } |
@Test public void deployWithPackageUri() throws Exception { final FunctionApp app = mock(FunctionApp.class); final DeployTarget deployTarget = mock(DeployTarget.class); final WithPackageUri withPackageUri = mock(WithPackageUri.class); doReturn(withPackageUri).when(app).deploy(); final WithExecute withExecute = mock(WithExecute.class); doReturn(withExecute).when(withPackageUri).withPackageUri(anyString()); doReturn(withExecute).when(withExecute).withExistingDeploymentsDeleted(false); final Runnable runnable = mock(Runnable.class); doNothing().when(deployTarget).msDeploy("uri", false); buildHandler(); handlerSpy.deployWithPackageUri(deployTarget, "uri", runnable); verify(handlerSpy, times(1)).deployWithPackageUri(deployTarget, "uri", runnable); verify(runnable, times(1)).run(); verify(deployTarget, times(1)).msDeploy("uri", false); } | protected void deployWithPackageUri(final DeployTarget target, final String packageUri, Runnable onDeployFinish) { try { Log.prompt(DEPLOY_PACKAGE_START); target.msDeploy(packageUri, false); Log.prompt(DEPLOY_PACKAGE_DONE); } finally { onDeployFinish.run(); } } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deployWithPackageUri(final DeployTarget target, final String packageUri, Runnable onDeployFinish) { try { Log.prompt(DEPLOY_PACKAGE_START); target.msDeploy(packageUri, false); Log.prompt(DEPLOY_PACKAGE_DONE); } finally { onDeployFinish.run(); } } } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deployWithPackageUri(final DeployTarget target, final String packageUri, Runnable onDeployFinish) { try { Log.prompt(DEPLOY_PACKAGE_START); target.msDeploy(packageUri, false); Log.prompt(DEPLOY_PACKAGE_DONE); } finally { onDeployFinish.run(); } } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deployWithPackageUri(final DeployTarget target, final String packageUri, Runnable onDeployFinish) { try { Log.prompt(DEPLOY_PACKAGE_START); target.msDeploy(packageUri, false); Log.prompt(DEPLOY_PACKAGE_DONE); } finally { onDeployFinish.run(); } } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deployWithPackageUri(final DeployTarget target, final String packageUri, Runnable onDeployFinish) { try { Log.prompt(DEPLOY_PACKAGE_START); target.msDeploy(packageUri, false); Log.prompt(DEPLOY_PACKAGE_DONE); } finally { onDeployFinish.run(); } } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); static final String DEPLOYMENT_PACKAGE_CONTAINER; static final String CREATE_ZIP_START; static final String CREATE_ZIP_DONE; static final String UPLOAD_PACKAGE_START; static final String UPLOAD_PACKAGE_DONE; static final String DEPLOY_PACKAGE_START; static final String DEPLOY_PACKAGE_DONE; static final String DELETE_PACKAGE_START; static final String DELETE_PACKAGE_DONE; static final String DELETE_PACKAGE_FAIL; } |
@Test public void deletePackageFromAzureStorage() throws Exception { final CloudStorageAccount storageAccount = mock(CloudStorageAccount.class); final CloudBlobClient blobClient = mock(CloudBlobClient.class); doReturn(blobClient).when(storageAccount).createCloudBlobClient(); final CloudBlobContainer blobContainer = mock(CloudBlobContainer.class); doReturn(blobContainer).when(blobClient).getContainerReference(anyString()); doReturn(true).when(blobContainer).exists(); final CloudBlockBlob blob = mock(CloudBlockBlob.class); doReturn(blob).when(blobContainer).getBlockBlobReference(anyString()); doReturn(true).when(blob).deleteIfExists(); buildHandler(); handler.deletePackageFromAzureStorage(storageAccount, "blob"); } | protected void deletePackageFromAzureStorage(final CloudStorageAccount storageAccount, final String blobName) { try { Log.prompt(DELETE_PACKAGE_START); AzureStorageHelper.deleteBlob(storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); Log.prompt(DELETE_PACKAGE_DONE + blobName); } catch (Exception e) { Log.error(DELETE_PACKAGE_FAIL + blobName); } } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deletePackageFromAzureStorage(final CloudStorageAccount storageAccount, final String blobName) { try { Log.prompt(DELETE_PACKAGE_START); AzureStorageHelper.deleteBlob(storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); Log.prompt(DELETE_PACKAGE_DONE + blobName); } catch (Exception e) { Log.error(DELETE_PACKAGE_FAIL + blobName); } } } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deletePackageFromAzureStorage(final CloudStorageAccount storageAccount, final String blobName) { try { Log.prompt(DELETE_PACKAGE_START); AzureStorageHelper.deleteBlob(storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); Log.prompt(DELETE_PACKAGE_DONE + blobName); } catch (Exception e) { Log.error(DELETE_PACKAGE_FAIL + blobName); } } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deletePackageFromAzureStorage(final CloudStorageAccount storageAccount, final String blobName) { try { Log.prompt(DELETE_PACKAGE_START); AzureStorageHelper.deleteBlob(storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); Log.prompt(DELETE_PACKAGE_DONE + blobName); } catch (Exception e) { Log.error(DELETE_PACKAGE_FAIL + blobName); } } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); } | MSDeployArtifactHandlerImpl extends ArtifactHandlerBase { protected void deletePackageFromAzureStorage(final CloudStorageAccount storageAccount, final String blobName) { try { Log.prompt(DELETE_PACKAGE_START); AzureStorageHelper.deleteBlob(storageAccount, DEPLOYMENT_PACKAGE_CONTAINER, blobName); Log.prompt(DELETE_PACKAGE_DONE + blobName); } catch (Exception e) { Log.error(DELETE_PACKAGE_FAIL + blobName); } } private MSDeployArtifactHandlerImpl(@Nonnull final Builder builder); @Override void publish(final DeployTarget target); static final String DEPLOYMENT_PACKAGE_CONTAINER; static final String CREATE_ZIP_START; static final String CREATE_ZIP_DONE; static final String UPLOAD_PACKAGE_START; static final String UPLOAD_PACKAGE_DONE; static final String DEPLOY_PACKAGE_START; static final String DEPLOY_PACKAGE_DONE; static final String DELETE_PACKAGE_START; static final String DELETE_PACKAGE_DONE; static final String DELETE_PACKAGE_FAIL; } |
@Test public void testGetCloudStorageAccount() throws Exception { final String storageConnection = "DefaultEndpointsProtocol=https;AccountName=123456;AccountKey=12345678;EndpointSuffix=core.windows.net"; final Map mapSettings = mock(Map.class); final DeployTarget deployTarget = mock(DeployTarget.class); final AppSetting storageSetting = mock(AppSetting.class); mapSettings.put(INTERNAL_STORAGE_KEY, storageSetting); doReturn(mapSettings).when(deployTarget).getAppSettings(); doReturn(storageSetting).when(mapSettings).get(anyString()); doReturn(storageConnection).when(storageSetting).value(); final CloudStorageAccount storageAccount = FunctionArtifactHelper.getCloudStorageAccount(deployTarget); assertNotNull(storageAccount); } | public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } |
@Test public void updateFunctionApp() throws Exception { final FunctionApp app = mock(FunctionApp.class); final Update update = mock(Update.class); doNothing().when(mojoSpy).configureAppSettings(any(Consumer.class), anyMap()); final FunctionRuntimeHandler functionRuntimeHandler = mock(WindowsFunctionRuntimeHandler.class); doReturn(update).when(functionRuntimeHandler).updateAppRuntime(app); mojoSpy.updateFunctionApp(app, functionRuntimeHandler); verify(update, times(1)).apply(); } | protected FunctionApp updateFunctionApp(final FunctionApp app, final FunctionRuntimeHandler runtimeHandler) throws AzureAuthFailureException, AzureExecutionException { Log.info(FUNCTION_APP_UPDATE); runtimeHandler.updateAppServicePlan(app); final Update update = runtimeHandler.updateAppRuntime(app); updateFunctionAppSettings(update); final FunctionApp result = update.apply(); Log.info(String.format(FUNCTION_APP_UPDATE_DONE, getAppName())); return result; } | DeployMojo extends AbstractFunctionMojo { protected FunctionApp updateFunctionApp(final FunctionApp app, final FunctionRuntimeHandler runtimeHandler) throws AzureAuthFailureException, AzureExecutionException { Log.info(FUNCTION_APP_UPDATE); runtimeHandler.updateAppServicePlan(app); final Update update = runtimeHandler.updateAppRuntime(app); updateFunctionAppSettings(update); final FunctionApp result = update.apply(); Log.info(String.format(FUNCTION_APP_UPDATE_DONE, getAppName())); return result; } } | DeployMojo extends AbstractFunctionMojo { protected FunctionApp updateFunctionApp(final FunctionApp app, final FunctionRuntimeHandler runtimeHandler) throws AzureAuthFailureException, AzureExecutionException { Log.info(FUNCTION_APP_UPDATE); runtimeHandler.updateAppServicePlan(app); final Update update = runtimeHandler.updateAppRuntime(app); updateFunctionAppSettings(update); final FunctionApp result = update.apply(); Log.info(String.format(FUNCTION_APP_UPDATE_DONE, getAppName())); return result; } } | DeployMojo extends AbstractFunctionMojo { protected FunctionApp updateFunctionApp(final FunctionApp app, final FunctionRuntimeHandler runtimeHandler) throws AzureAuthFailureException, AzureExecutionException { Log.info(FUNCTION_APP_UPDATE); runtimeHandler.updateAppServicePlan(app); final Update update = runtimeHandler.updateAppRuntime(app); updateFunctionAppSettings(update); final FunctionApp result = update.apply(); Log.info(String.format(FUNCTION_APP_UPDATE_DONE, getAppName())); return result; } @Override DeploymentType getDeploymentType(); } | DeployMojo extends AbstractFunctionMojo { protected FunctionApp updateFunctionApp(final FunctionApp app, final FunctionRuntimeHandler runtimeHandler) throws AzureAuthFailureException, AzureExecutionException { Log.info(FUNCTION_APP_UPDATE); runtimeHandler.updateAppServicePlan(app); final Update update = runtimeHandler.updateAppRuntime(app); updateFunctionAppSettings(update); final FunctionApp result = update.apply(); Log.info(String.format(FUNCTION_APP_UPDATE_DONE, getAppName())); return result; } @Override DeploymentType getDeploymentType(); } |
@Test public void testGetCloudStorageAccountWithException() { final FunctionApp app = mock(FunctionApp.class); final DeployTarget deployTarget = mock(DeployTarget.class); final Map appSettings = mock(Map.class); doReturn(appSettings).when(app).getAppSettings(); doReturn(null).when(appSettings).get(anyString()); String exceptionMessage = null; try { FunctionArtifactHelper.getCloudStorageAccount(deployTarget); } catch (Exception e) { exceptionMessage = e.getMessage(); } finally { assertEquals("Application setting 'AzureWebJobsStorage' not found.", exceptionMessage); } } | public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } | FunctionArtifactHelper { public static CloudStorageAccount getCloudStorageAccount(final DeployTarget target) throws AzureExecutionException { final Map<String, AppSetting> settingsMap = target.getAppSettings(); if (settingsMap != null) { final AppSetting setting = settingsMap.get(INTERNAL_STORAGE_KEY); if (setting != null) { final String value = setting.value(); if (StringUtils.isNotEmpty(value)) { try { return CloudStorageAccount.parse(value); } catch (InvalidKeyException | URISyntaxException e) { throw new AzureExecutionException("Cannot parse storage connection string due to error: " + e.getMessage(), e); } } } } throw new AzureExecutionException(INTERNAL_STORAGE_NOT_FOUND); } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } |
@Test public void testUpdateAppSetting() throws Exception { final DeployTarget deployTarget = mock(DeployTarget.class); final FunctionApp functionApp = mock(FunctionApp.class); doReturn(functionApp).when(deployTarget).getApp(); final FunctionApp.Update update = mock(FunctionApp.Update.class); doReturn(update).when(functionApp).update(); doReturn(update).when(update).withAppSetting(any(), any()); doReturn(functionApp).when(update).apply(); final String appSettingKey = "KEY"; final String appSettingValue = "VALUE"; FunctionArtifactHelper.updateAppSetting(deployTarget, appSettingKey, appSettingValue); verify(deployTarget, times(1)).getApp(); verify(functionApp, times(1)).update(); verify(update, times(1)).withAppSetting(appSettingKey, appSettingValue); verify(update, times(1)).apply(); verifyNoMoreInteractions(update); verifyNoMoreInteractions(functionApp); verifyNoMoreInteractions(deployTarget); } | public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } |
@Test public void testUpdateAppSettingWithException() { final DeployTarget deployTarget = mock(DeployTarget.class); final WebApp webapp = mock(WebApp.class); doReturn(webapp).when(deployTarget).getApp(); final String appSettingKey = "KEY"; final String appSettingValue = "VALUE"; String exceptionMessage = null; try { FunctionArtifactHelper.updateAppSetting(deployTarget, appSettingKey, appSettingValue); } catch (Exception e) { exceptionMessage = e.getMessage(); } finally { assertEquals("Unsupported deployment target, only function is supported", exceptionMessage); } } | public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } | FunctionArtifactHelper { public static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value) throws AzureExecutionException { final WebAppBase targetApp = deployTarget.getApp(); if (targetApp instanceof FunctionApp) { ((FunctionApp) targetApp).update().withAppSetting(key, value).apply(); } else if (targetApp instanceof FunctionDeploymentSlot) { ((FunctionDeploymentSlot) targetApp).update().withAppSetting(key, value).apply(); } else { throw new AzureExecutionException(UNSUPPORTED_DEPLOYMENT_TARGET); } } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } |
@Test public void testCreateFunctionArtifactWithException() { String exceptionMessage = null; try { FunctionArtifactHelper.createFunctionArtifact(""); } catch (Exception e) { exceptionMessage = e.getMessage(); } finally { assertEquals("Azure Functions stage directory not found. Please run 'mvn clean" + " azure-functions:package' first.", exceptionMessage); } } | public static File createFunctionArtifact(final String stagingDirectoryPath) throws AzureExecutionException { final File stageDirectory = new File(stagingDirectoryPath); final File zipPackage = new File(stagingDirectoryPath.concat(Constants.ZIP_EXT)); if (!stageDirectory.exists() || !stageDirectory.isDirectory()) { throw new AzureExecutionException(STAGE_DIR_NOT_FOUND); } ZipUtil.pack(stageDirectory, zipPackage); ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE); return zipPackage; } | FunctionArtifactHelper { public static File createFunctionArtifact(final String stagingDirectoryPath) throws AzureExecutionException { final File stageDirectory = new File(stagingDirectoryPath); final File zipPackage = new File(stagingDirectoryPath.concat(Constants.ZIP_EXT)); if (!stageDirectory.exists() || !stageDirectory.isDirectory()) { throw new AzureExecutionException(STAGE_DIR_NOT_FOUND); } ZipUtil.pack(stageDirectory, zipPackage); ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE); return zipPackage; } } | FunctionArtifactHelper { public static File createFunctionArtifact(final String stagingDirectoryPath) throws AzureExecutionException { final File stageDirectory = new File(stagingDirectoryPath); final File zipPackage = new File(stagingDirectoryPath.concat(Constants.ZIP_EXT)); if (!stageDirectory.exists() || !stageDirectory.isDirectory()) { throw new AzureExecutionException(STAGE_DIR_NOT_FOUND); } ZipUtil.pack(stageDirectory, zipPackage); ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE); return zipPackage; } } | FunctionArtifactHelper { public static File createFunctionArtifact(final String stagingDirectoryPath) throws AzureExecutionException { final File stageDirectory = new File(stagingDirectoryPath); final File zipPackage = new File(stagingDirectoryPath.concat(Constants.ZIP_EXT)); if (!stageDirectory.exists() || !stageDirectory.isDirectory()) { throw new AzureExecutionException(STAGE_DIR_NOT_FOUND); } ZipUtil.pack(stageDirectory, zipPackage); ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE); return zipPackage; } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } | FunctionArtifactHelper { public static File createFunctionArtifact(final String stagingDirectoryPath) throws AzureExecutionException { final File stageDirectory = new File(stagingDirectoryPath); final File zipPackage = new File(stagingDirectoryPath.concat(Constants.ZIP_EXT)); if (!stageDirectory.exists() || !stageDirectory.isDirectory()) { throw new AzureExecutionException(STAGE_DIR_NOT_FOUND); } ZipUtil.pack(stageDirectory, zipPackage); ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE); return zipPackage; } static File createFunctionArtifact(final String stagingDirectoryPath); static void updateAppSetting(final DeployTarget deployTarget, final String key, final String value); static CloudStorageAccount getCloudStorageAccount(final DeployTarget target); } |
@Test public void installExtension() throws Exception { final CommandHandler commandHandler = mock(CommandHandler.class); final FunctionCoreToolsHandlerImpl functionCoreToolsHandler = new FunctionCoreToolsHandlerImpl(commandHandler); final FunctionCoreToolsHandlerImpl functionCoreToolsHandlerSpy = spy(functionCoreToolsHandler); doReturn("3.0.0").when(functionCoreToolsHandlerSpy).getLocalFunctionCoreToolsVersion(); doReturn("3.0.0").when(functionCoreToolsHandlerSpy).getLatestFunctionCoreToolsVersion(); doNothing().when(functionCoreToolsHandlerSpy).installFunctionExtension(new File("folder1"), new File("folder2")); functionCoreToolsHandlerSpy.installExtension(new File("folder1"), new File("folder2")); } | @Override public void installExtension(File stagingDirectory, File basedir) throws AzureExecutionException { assureRequirementAddressed(); installFunctionExtension(stagingDirectory, basedir); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { @Override public void installExtension(File stagingDirectory, File basedir) throws AzureExecutionException { assureRequirementAddressed(); installFunctionExtension(stagingDirectory, basedir); } } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { @Override public void installExtension(File stagingDirectory, File basedir) throws AzureExecutionException { assureRequirementAddressed(); installFunctionExtension(stagingDirectory, basedir); } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { @Override public void installExtension(File stagingDirectory, File basedir) throws AzureExecutionException { assureRequirementAddressed(); installFunctionExtension(stagingDirectory, basedir); } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { @Override public void installExtension(File stagingDirectory, File basedir) throws AzureExecutionException { assureRequirementAddressed(); installFunctionExtension(stagingDirectory, basedir); } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); static final String FUNC_EXTENSIONS_INSTALL_TEMPLATE; static final String INSTALL_FUNCTION_EXTENSIONS_FAIL; static final String CANNOT_AUTO_INSTALL; static final String NEED_UPDATE_FUNCTION_CORE_TOOLS; static final String GET_LATEST_VERSION_CMD; static final String GET_LATEST_VERSION_FAIL; static final String GET_LOCAL_VERSION_CMD; static final String GET_LOCAL_VERSION_FAIL; static final Version LEAST_SUPPORTED_VERSION; } |
@Test public void getLocalFunctionCoreToolsVersion() throws Exception { final CommandHandler commandHandler = mock(CommandHandler.class); final FunctionCoreToolsHandlerImpl functionCoreToolsHandler = new FunctionCoreToolsHandlerImpl(commandHandler); final FunctionCoreToolsHandlerImpl functionCoreToolsHandlerSpy = spy(functionCoreToolsHandler); doReturn("2.0.1-beta.26") .when(commandHandler).runCommandAndGetOutput(anyString(), anyBoolean(), any()); assertEquals("2.0.1-beta.26", functionCoreToolsHandlerSpy.getLocalFunctionCoreToolsVersion()); } | protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); static final String FUNC_EXTENSIONS_INSTALL_TEMPLATE; static final String INSTALL_FUNCTION_EXTENSIONS_FAIL; static final String CANNOT_AUTO_INSTALL; static final String NEED_UPDATE_FUNCTION_CORE_TOOLS; static final String GET_LATEST_VERSION_CMD; static final String GET_LATEST_VERSION_FAIL; static final String GET_LOCAL_VERSION_CMD; static final String GET_LOCAL_VERSION_FAIL; static final Version LEAST_SUPPORTED_VERSION; } |
@Test public void getLocalFunctionCoreToolsVersionFailed() throws Exception { final CommandHandler commandHandler = mock(CommandHandler.class); final FunctionCoreToolsHandlerImpl functionCoreToolsHandler = new FunctionCoreToolsHandlerImpl(commandHandler); final FunctionCoreToolsHandlerImpl functionCoreToolsHandlerSpy = spy(functionCoreToolsHandler); doReturn("unexpected output") .when(commandHandler).runCommandAndGetOutput(anyString(), anyBoolean(), any()); assertNull(functionCoreToolsHandlerSpy.getLocalFunctionCoreToolsVersion()); } | protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected String getLocalFunctionCoreToolsVersion() { try { final String localVersion = commandHandler.runCommandAndGetOutput( GET_LOCAL_VERSION_CMD, false, null ); Version.valueOf(localVersion); return localVersion; } catch (Exception e) { Log.warn(GET_LOCAL_VERSION_FAIL); return null; } } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); static final String FUNC_EXTENSIONS_INSTALL_TEMPLATE; static final String INSTALL_FUNCTION_EXTENSIONS_FAIL; static final String CANNOT_AUTO_INSTALL; static final String NEED_UPDATE_FUNCTION_CORE_TOOLS; static final String GET_LATEST_VERSION_CMD; static final String GET_LATEST_VERSION_FAIL; static final String GET_LOCAL_VERSION_CMD; static final String GET_LOCAL_VERSION_FAIL; static final Version LEAST_SUPPORTED_VERSION; } |
@Test public void installFunctionExtension() throws Exception { final CommandHandler commandHandler = mock(CommandHandler.class); final FunctionCoreToolsHandlerImpl functionCoreToolsHandler = new FunctionCoreToolsHandlerImpl(commandHandler); final FunctionCoreToolsHandlerImpl functionCoreToolsHandlerSpy = spy(functionCoreToolsHandler); doNothing().when(commandHandler).runCommandWithReturnCodeCheck(anyString(), anyBoolean(), any(), ArgumentMatchers.anyList(), anyString()); functionCoreToolsHandlerSpy.installFunctionExtension(new File("path1"), new File("path2")); verify(commandHandler, times(1)).runCommandWithReturnCodeCheck( String.format(FUNC_EXTENSIONS_INSTALL_TEMPLATE, new File("path2").getAbsolutePath()), true, new File("path1").getAbsolutePath(), CommandUtils.getDefaultValidReturnCodes(), INSTALL_FUNCTION_EXTENSIONS_FAIL ); } | protected void installFunctionExtension(File stagingDirector, File basedir) throws AzureExecutionException { commandHandler.runCommandWithReturnCodeCheck( String.format(FUNC_EXTENSIONS_INSTALL_TEMPLATE, basedir.getAbsolutePath()), true, stagingDirector.getAbsolutePath(), CommandUtils.getDefaultValidReturnCodes(), INSTALL_FUNCTION_EXTENSIONS_FAIL ); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected void installFunctionExtension(File stagingDirector, File basedir) throws AzureExecutionException { commandHandler.runCommandWithReturnCodeCheck( String.format(FUNC_EXTENSIONS_INSTALL_TEMPLATE, basedir.getAbsolutePath()), true, stagingDirector.getAbsolutePath(), CommandUtils.getDefaultValidReturnCodes(), INSTALL_FUNCTION_EXTENSIONS_FAIL ); } } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected void installFunctionExtension(File stagingDirector, File basedir) throws AzureExecutionException { commandHandler.runCommandWithReturnCodeCheck( String.format(FUNC_EXTENSIONS_INSTALL_TEMPLATE, basedir.getAbsolutePath()), true, stagingDirector.getAbsolutePath(), CommandUtils.getDefaultValidReturnCodes(), INSTALL_FUNCTION_EXTENSIONS_FAIL ); } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected void installFunctionExtension(File stagingDirector, File basedir) throws AzureExecutionException { commandHandler.runCommandWithReturnCodeCheck( String.format(FUNC_EXTENSIONS_INSTALL_TEMPLATE, basedir.getAbsolutePath()), true, stagingDirector.getAbsolutePath(), CommandUtils.getDefaultValidReturnCodes(), INSTALL_FUNCTION_EXTENSIONS_FAIL ); } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); } | FunctionCoreToolsHandlerImpl implements FunctionCoreToolsHandler { protected void installFunctionExtension(File stagingDirector, File basedir) throws AzureExecutionException { commandHandler.runCommandWithReturnCodeCheck( String.format(FUNC_EXTENSIONS_INSTALL_TEMPLATE, basedir.getAbsolutePath()), true, stagingDirector.getAbsolutePath(), CommandUtils.getDefaultValidReturnCodes(), INSTALL_FUNCTION_EXTENSIONS_FAIL ); } FunctionCoreToolsHandlerImpl(final CommandHandler commandHandler); @Override void installExtension(File stagingDirectory, File basedir); static final String FUNC_EXTENSIONS_INSTALL_TEMPLATE; static final String INSTALL_FUNCTION_EXTENSIONS_FAIL; static final String CANNOT_AUTO_INSTALL; static final String NEED_UPDATE_FUNCTION_CORE_TOOLS; static final String GET_LATEST_VERSION_CMD; static final String GET_LATEST_VERSION_FAIL; static final String GET_LOCAL_VERSION_CMD; static final String GET_LOCAL_VERSION_FAIL; static final Version LEAST_SUPPORTED_VERSION; } |
@Test public void buildCommand() { assertEquals(3, CommandHandlerImpl.buildCommand("cmd").length); } | protected static String[] buildCommand(final String command) { return CommandUtils.isWindows() ? new String[]{"cmd.exe", "/c", command} : new String[]{"sh", "-c", command}; } | CommandHandlerImpl implements CommandHandler { protected static String[] buildCommand(final String command) { return CommandUtils.isWindows() ? new String[]{"cmd.exe", "/c", command} : new String[]{"sh", "-c", command}; } } | CommandHandlerImpl implements CommandHandler { protected static String[] buildCommand(final String command) { return CommandUtils.isWindows() ? new String[]{"cmd.exe", "/c", command} : new String[]{"sh", "-c", command}; } } | CommandHandlerImpl implements CommandHandler { protected static String[] buildCommand(final String command) { return CommandUtils.isWindows() ? new String[]{"cmd.exe", "/c", command} : new String[]{"sh", "-c", command}; } @Override void runCommandWithReturnCodeCheck(final String command,
final boolean showStdout,
final String workingDirectory,
final List<Long> validReturnCodes,
final String errorMessage); @Override String runCommandAndGetOutput(final String command,
final boolean showStdout,
final String workingDirectory); } | CommandHandlerImpl implements CommandHandler { protected static String[] buildCommand(final String command) { return CommandUtils.isWindows() ? new String[]{"cmd.exe", "/c", command} : new String[]{"sh", "-c", command}; } @Override void runCommandWithReturnCodeCheck(final String command,
final boolean showStdout,
final String workingDirectory,
final List<Long> validReturnCodes,
final String errorMessage); @Override String runCommandAndGetOutput(final String command,
final boolean showStdout,
final String workingDirectory); } |
@Test public void getStdoutRedirect() { assertEquals(ProcessBuilder.Redirect.INHERIT, CommandHandlerImpl.getStdoutRedirect(true)); assertEquals(ProcessBuilder.Redirect.PIPE, CommandHandlerImpl.getStdoutRedirect(false)); } | protected static ProcessBuilder.Redirect getStdoutRedirect(boolean showStdout) { return showStdout ? ProcessBuilder.Redirect.INHERIT : ProcessBuilder.Redirect.PIPE; } | CommandHandlerImpl implements CommandHandler { protected static ProcessBuilder.Redirect getStdoutRedirect(boolean showStdout) { return showStdout ? ProcessBuilder.Redirect.INHERIT : ProcessBuilder.Redirect.PIPE; } } | CommandHandlerImpl implements CommandHandler { protected static ProcessBuilder.Redirect getStdoutRedirect(boolean showStdout) { return showStdout ? ProcessBuilder.Redirect.INHERIT : ProcessBuilder.Redirect.PIPE; } } | CommandHandlerImpl implements CommandHandler { protected static ProcessBuilder.Redirect getStdoutRedirect(boolean showStdout) { return showStdout ? ProcessBuilder.Redirect.INHERIT : ProcessBuilder.Redirect.PIPE; } @Override void runCommandWithReturnCodeCheck(final String command,
final boolean showStdout,
final String workingDirectory,
final List<Long> validReturnCodes,
final String errorMessage); @Override String runCommandAndGetOutput(final String command,
final boolean showStdout,
final String workingDirectory); } | CommandHandlerImpl implements CommandHandler { protected static ProcessBuilder.Redirect getStdoutRedirect(boolean showStdout) { return showStdout ? ProcessBuilder.Redirect.INHERIT : ProcessBuilder.Redirect.PIPE; } @Override void runCommandWithReturnCodeCheck(final String command,
final boolean showStdout,
final String workingDirectory,
final List<Long> validReturnCodes,
final String errorMessage); @Override String runCommandAndGetOutput(final String command,
final boolean showStdout,
final String workingDirectory); } |
@Test public void configureAppSettings() throws Exception { final WithCreate withCreate = mock(WithCreate.class); mojo.configureAppSettings(withCreate::withAppSettings, mojo.getAppSettingsWithDefaultValue()); verify(withCreate, times(1)).withAppSettings(anyMap()); } | protected void configureAppSettings(final Consumer<Map> withAppSettings, final Map appSettings) { if (appSettings != null && !appSettings.isEmpty()) { withAppSettings.accept(appSettings); } } | DeployMojo extends AbstractFunctionMojo { protected void configureAppSettings(final Consumer<Map> withAppSettings, final Map appSettings) { if (appSettings != null && !appSettings.isEmpty()) { withAppSettings.accept(appSettings); } } } | DeployMojo extends AbstractFunctionMojo { protected void configureAppSettings(final Consumer<Map> withAppSettings, final Map appSettings) { if (appSettings != null && !appSettings.isEmpty()) { withAppSettings.accept(appSettings); } } } | DeployMojo extends AbstractFunctionMojo { protected void configureAppSettings(final Consumer<Map> withAppSettings, final Map appSettings) { if (appSettings != null && !appSettings.isEmpty()) { withAppSettings.accept(appSettings); } } @Override DeploymentType getDeploymentType(); } | DeployMojo extends AbstractFunctionMojo { protected void configureAppSettings(final Consumer<Map> withAppSettings, final Map appSettings) { if (appSettings != null && !appSettings.isEmpty()) { withAppSettings.accept(appSettings); } } @Override DeploymentType getDeploymentType(); } |
@Test(expected = Exception.class) public void handleExitValue() throws Exception { final CommandHandlerImpl handler = new CommandHandlerImpl(); handler.handleExitValue(1, Arrays.asList(0L), "", null); } | protected void handleExitValue(int exitValue, final List<Long> validReturnCodes, final String errorMessage, final InputStream inputStream) throws AzureExecutionException, IOException { Log.debug("Process exit value: " + exitValue); if (!validReturnCodes.contains(Integer.toUnsignedLong(exitValue))) { showErrorIfAny(inputStream); Log.error(errorMessage); throw new AzureExecutionException(errorMessage); } } | CommandHandlerImpl implements CommandHandler { protected void handleExitValue(int exitValue, final List<Long> validReturnCodes, final String errorMessage, final InputStream inputStream) throws AzureExecutionException, IOException { Log.debug("Process exit value: " + exitValue); if (!validReturnCodes.contains(Integer.toUnsignedLong(exitValue))) { showErrorIfAny(inputStream); Log.error(errorMessage); throw new AzureExecutionException(errorMessage); } } } | CommandHandlerImpl implements CommandHandler { protected void handleExitValue(int exitValue, final List<Long> validReturnCodes, final String errorMessage, final InputStream inputStream) throws AzureExecutionException, IOException { Log.debug("Process exit value: " + exitValue); if (!validReturnCodes.contains(Integer.toUnsignedLong(exitValue))) { showErrorIfAny(inputStream); Log.error(errorMessage); throw new AzureExecutionException(errorMessage); } } } | CommandHandlerImpl implements CommandHandler { protected void handleExitValue(int exitValue, final List<Long> validReturnCodes, final String errorMessage, final InputStream inputStream) throws AzureExecutionException, IOException { Log.debug("Process exit value: " + exitValue); if (!validReturnCodes.contains(Integer.toUnsignedLong(exitValue))) { showErrorIfAny(inputStream); Log.error(errorMessage); throw new AzureExecutionException(errorMessage); } } @Override void runCommandWithReturnCodeCheck(final String command,
final boolean showStdout,
final String workingDirectory,
final List<Long> validReturnCodes,
final String errorMessage); @Override String runCommandAndGetOutput(final String command,
final boolean showStdout,
final String workingDirectory); } | CommandHandlerImpl implements CommandHandler { protected void handleExitValue(int exitValue, final List<Long> validReturnCodes, final String errorMessage, final InputStream inputStream) throws AzureExecutionException, IOException { Log.debug("Process exit value: " + exitValue); if (!validReturnCodes.contains(Integer.toUnsignedLong(exitValue))) { showErrorIfAny(inputStream); Log.error(errorMessage); throw new AzureExecutionException(errorMessage); } } @Override void runCommandWithReturnCodeCheck(final String command,
final boolean showStdout,
final String workingDirectory,
final List<Long> validReturnCodes,
final String errorMessage); @Override String runCommandAndGetOutput(final String command,
final boolean showStdout,
final String workingDirectory); } |
@Test public void isWindows() { assertEquals(SystemUtils.IS_OS_WINDOWS, CommandUtils.isWindows()); } | public static boolean isWindows() { return SystemUtils.IS_OS_WINDOWS; } | CommandUtils { public static boolean isWindows() { return SystemUtils.IS_OS_WINDOWS; } } | CommandUtils { public static boolean isWindows() { return SystemUtils.IS_OS_WINDOWS; } } | CommandUtils { public static boolean isWindows() { return SystemUtils.IS_OS_WINDOWS; } static boolean isWindows(); static List<Long> getDefaultValidReturnCodes(); static List<Long> getValidReturnCodes(); } | CommandUtils { public static boolean isWindows() { return SystemUtils.IS_OS_WINDOWS; } static boolean isWindows(); static List<Long> getDefaultValidReturnCodes(); static List<Long> getValidReturnCodes(); } |
@Test public void getDefaultValidReturnCodes() throws Exception { assertEquals(2, CommandUtils.getValidReturnCodes().size()); assertEquals(true, CommandUtils.getValidReturnCodes().contains(0L)); } | public static List<Long> getDefaultValidReturnCodes() { return Arrays.asList(0L); } | CommandUtils { public static List<Long> getDefaultValidReturnCodes() { return Arrays.asList(0L); } } | CommandUtils { public static List<Long> getDefaultValidReturnCodes() { return Arrays.asList(0L); } } | CommandUtils { public static List<Long> getDefaultValidReturnCodes() { return Arrays.asList(0L); } static boolean isWindows(); static List<Long> getDefaultValidReturnCodes(); static List<Long> getValidReturnCodes(); } | CommandUtils { public static List<Long> getDefaultValidReturnCodes() { return Arrays.asList(0L); } static boolean isWindows(); static List<Long> getDefaultValidReturnCodes(); static List<Long> getValidReturnCodes(); } |
@Test public void getValidReturnCodes() { assertEquals(Arrays.asList(0L), CommandUtils.getDefaultValidReturnCodes()); } | public static List<Long> getValidReturnCodes() { return isWindows() ? Arrays.asList(0L, 3221225786L) : Arrays.asList(0L, 130L); } | CommandUtils { public static List<Long> getValidReturnCodes() { return isWindows() ? Arrays.asList(0L, 3221225786L) : Arrays.asList(0L, 130L); } } | CommandUtils { public static List<Long> getValidReturnCodes() { return isWindows() ? Arrays.asList(0L, 3221225786L) : Arrays.asList(0L, 130L); } } | CommandUtils { public static List<Long> getValidReturnCodes() { return isWindows() ? Arrays.asList(0L, 3221225786L) : Arrays.asList(0L, 130L); } static boolean isWindows(); static List<Long> getDefaultValidReturnCodes(); static List<Long> getValidReturnCodes(); } | CommandUtils { public static List<Long> getValidReturnCodes() { return isWindows() ? Arrays.asList(0L, 3221225786L) : Arrays.asList(0L, 130L); } static boolean isWindows(); static List<Long> getDefaultValidReturnCodes(); static List<Long> getValidReturnCodes(); } |
@Test public void uploadDirectoryWithRetries() throws Exception { final FTPUploader uploaderSpy = spy(ftpUploader); AzureExecutionException exception = null; doReturn(false).when(uploaderSpy).uploadDirectory(anyString(), anyString(), anyString(), anyString(), anyString()); try { uploaderSpy.uploadDirectoryWithRetries("ftpServer", "username", "password", "sourceDir", "targetDir", 1); } catch (AzureExecutionException e) { exception = e; } finally { assertNotNull(exception); } doReturn(true).when(uploaderSpy).uploadDirectory(anyString(), anyString(), anyString(), anyString(), anyString()); uploaderSpy.uploadDirectoryWithRetries("ftpServer", "username", "password", "sourceDir", "targetDir", 1); } | public void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password, final String sourceDirectory, final String targetDirectory, final int maxRetryCount) throws AzureExecutionException { int retryCount = 0; while (retryCount < maxRetryCount) { retryCount++; Log.prompt(UPLOAD_START + ftpServer); if (uploadDirectory(ftpServer, username, password, sourceDirectory, targetDirectory)) { Log.prompt(UPLOAD_SUCCESS + ftpServer); return; } else { Log.warn(String.format(UPLOAD_FAILURE, retryCount, maxRetryCount)); } } throw new AzureExecutionException(String.format(UPLOAD_RETRY_FAILURE, maxRetryCount)); } | FTPUploader { public void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password, final String sourceDirectory, final String targetDirectory, final int maxRetryCount) throws AzureExecutionException { int retryCount = 0; while (retryCount < maxRetryCount) { retryCount++; Log.prompt(UPLOAD_START + ftpServer); if (uploadDirectory(ftpServer, username, password, sourceDirectory, targetDirectory)) { Log.prompt(UPLOAD_SUCCESS + ftpServer); return; } else { Log.warn(String.format(UPLOAD_FAILURE, retryCount, maxRetryCount)); } } throw new AzureExecutionException(String.format(UPLOAD_RETRY_FAILURE, maxRetryCount)); } } | FTPUploader { public void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password, final String sourceDirectory, final String targetDirectory, final int maxRetryCount) throws AzureExecutionException { int retryCount = 0; while (retryCount < maxRetryCount) { retryCount++; Log.prompt(UPLOAD_START + ftpServer); if (uploadDirectory(ftpServer, username, password, sourceDirectory, targetDirectory)) { Log.prompt(UPLOAD_SUCCESS + ftpServer); return; } else { Log.warn(String.format(UPLOAD_FAILURE, retryCount, maxRetryCount)); } } throw new AzureExecutionException(String.format(UPLOAD_RETRY_FAILURE, maxRetryCount)); } } | FTPUploader { public void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password, final String sourceDirectory, final String targetDirectory, final int maxRetryCount) throws AzureExecutionException { int retryCount = 0; while (retryCount < maxRetryCount) { retryCount++; Log.prompt(UPLOAD_START + ftpServer); if (uploadDirectory(ftpServer, username, password, sourceDirectory, targetDirectory)) { Log.prompt(UPLOAD_SUCCESS + ftpServer); return; } else { Log.warn(String.format(UPLOAD_FAILURE, retryCount, maxRetryCount)); } } throw new AzureExecutionException(String.format(UPLOAD_RETRY_FAILURE, maxRetryCount)); } void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password,
final String sourceDirectory, final String targetDirectory,
final int maxRetryCount); } | FTPUploader { public void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password, final String sourceDirectory, final String targetDirectory, final int maxRetryCount) throws AzureExecutionException { int retryCount = 0; while (retryCount < maxRetryCount) { retryCount++; Log.prompt(UPLOAD_START + ftpServer); if (uploadDirectory(ftpServer, username, password, sourceDirectory, targetDirectory)) { Log.prompt(UPLOAD_SUCCESS + ftpServer); return; } else { Log.warn(String.format(UPLOAD_FAILURE, retryCount, maxRetryCount)); } } throw new AzureExecutionException(String.format(UPLOAD_RETRY_FAILURE, maxRetryCount)); } void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password,
final String sourceDirectory, final String targetDirectory,
final int maxRetryCount); static final String UPLOAD_START; static final String UPLOAD_SUCCESS; static final String UPLOAD_FAILURE; static final String UPLOAD_RETRY_FAILURE; static final String UPLOAD_DIR_START; static final String UPLOAD_DIR_FINISH; static final String UPLOAD_DIR_FAILURE; static final String UPLOAD_DIR; static final String UPLOAD_FILE; static final String UPLOAD_FILE_REPLY; } |
@Test public void uploadDirectory() throws Exception { final FTPUploader uploaderSpy = spy(ftpUploader); final FTPClient ftpClient = mock(FTPClient.class); doReturn(ftpClient).when(uploaderSpy).getFTPClient(anyString(), anyString(), anyString()); doNothing().when(uploaderSpy).uploadDirectory(any(FTPClient.class), anyString(), anyString(), anyString()); uploaderSpy.uploadDirectory(anyString(), anyString(), anyString(), anyString(), anyString()); verify(ftpClient, times(1)).disconnect(); verifyNoMoreInteractions(ftpClient); verify(uploaderSpy, times(1)).uploadDirectory(any(FTPClient.class), anyString(), anyString(), anyString()); verify(uploaderSpy, times(1)).getFTPClient(anyString(), anyString(), anyString()); verify(uploaderSpy, times(1)).uploadDirectory(anyString(), anyString(), anyString(), anyString(), anyString()); verifyNoMoreInteractions(uploaderSpy); } | protected boolean uploadDirectory(final String ftpServer, final String username, final String password, final String sourceDirectoryPath, final String targetDirectoryPath) { Log.debug("FTP username: " + username); try { final FTPClient ftpClient = getFTPClient(ftpServer, username, password); Log.prompt(String.format(UPLOAD_DIR_START, sourceDirectoryPath, targetDirectoryPath)); uploadDirectory(ftpClient, sourceDirectoryPath, targetDirectoryPath, ""); Log.prompt(String.format(UPLOAD_DIR_FINISH, sourceDirectoryPath, targetDirectoryPath)); ftpClient.disconnect(); return true; } catch (Exception e) { Log.debug(e); Log.error(String.format(UPLOAD_DIR_FAILURE, sourceDirectoryPath, targetDirectoryPath)); } return false; } | FTPUploader { protected boolean uploadDirectory(final String ftpServer, final String username, final String password, final String sourceDirectoryPath, final String targetDirectoryPath) { Log.debug("FTP username: " + username); try { final FTPClient ftpClient = getFTPClient(ftpServer, username, password); Log.prompt(String.format(UPLOAD_DIR_START, sourceDirectoryPath, targetDirectoryPath)); uploadDirectory(ftpClient, sourceDirectoryPath, targetDirectoryPath, ""); Log.prompt(String.format(UPLOAD_DIR_FINISH, sourceDirectoryPath, targetDirectoryPath)); ftpClient.disconnect(); return true; } catch (Exception e) { Log.debug(e); Log.error(String.format(UPLOAD_DIR_FAILURE, sourceDirectoryPath, targetDirectoryPath)); } return false; } } | FTPUploader { protected boolean uploadDirectory(final String ftpServer, final String username, final String password, final String sourceDirectoryPath, final String targetDirectoryPath) { Log.debug("FTP username: " + username); try { final FTPClient ftpClient = getFTPClient(ftpServer, username, password); Log.prompt(String.format(UPLOAD_DIR_START, sourceDirectoryPath, targetDirectoryPath)); uploadDirectory(ftpClient, sourceDirectoryPath, targetDirectoryPath, ""); Log.prompt(String.format(UPLOAD_DIR_FINISH, sourceDirectoryPath, targetDirectoryPath)); ftpClient.disconnect(); return true; } catch (Exception e) { Log.debug(e); Log.error(String.format(UPLOAD_DIR_FAILURE, sourceDirectoryPath, targetDirectoryPath)); } return false; } } | FTPUploader { protected boolean uploadDirectory(final String ftpServer, final String username, final String password, final String sourceDirectoryPath, final String targetDirectoryPath) { Log.debug("FTP username: " + username); try { final FTPClient ftpClient = getFTPClient(ftpServer, username, password); Log.prompt(String.format(UPLOAD_DIR_START, sourceDirectoryPath, targetDirectoryPath)); uploadDirectory(ftpClient, sourceDirectoryPath, targetDirectoryPath, ""); Log.prompt(String.format(UPLOAD_DIR_FINISH, sourceDirectoryPath, targetDirectoryPath)); ftpClient.disconnect(); return true; } catch (Exception e) { Log.debug(e); Log.error(String.format(UPLOAD_DIR_FAILURE, sourceDirectoryPath, targetDirectoryPath)); } return false; } void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password,
final String sourceDirectory, final String targetDirectory,
final int maxRetryCount); } | FTPUploader { protected boolean uploadDirectory(final String ftpServer, final String username, final String password, final String sourceDirectoryPath, final String targetDirectoryPath) { Log.debug("FTP username: " + username); try { final FTPClient ftpClient = getFTPClient(ftpServer, username, password); Log.prompt(String.format(UPLOAD_DIR_START, sourceDirectoryPath, targetDirectoryPath)); uploadDirectory(ftpClient, sourceDirectoryPath, targetDirectoryPath, ""); Log.prompt(String.format(UPLOAD_DIR_FINISH, sourceDirectoryPath, targetDirectoryPath)); ftpClient.disconnect(); return true; } catch (Exception e) { Log.debug(e); Log.error(String.format(UPLOAD_DIR_FAILURE, sourceDirectoryPath, targetDirectoryPath)); } return false; } void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password,
final String sourceDirectory, final String targetDirectory,
final int maxRetryCount); static final String UPLOAD_START; static final String UPLOAD_SUCCESS; static final String UPLOAD_FAILURE; static final String UPLOAD_RETRY_FAILURE; static final String UPLOAD_DIR_START; static final String UPLOAD_DIR_FINISH; static final String UPLOAD_DIR_FAILURE; static final String UPLOAD_DIR; static final String UPLOAD_FILE; static final String UPLOAD_FILE_REPLY; } |
@Test public void getFTPClient() throws Exception { Exception caughtException = null; try { ftpUploader.getFTPClient("fakeFTPServer", "username", "password"); } catch (Exception e) { caughtException = e; } finally { assertNotNull(caughtException); } } | protected FTPClient getFTPClient(final String ftpServer, final String username, final String password) throws IOException { final FTPClient ftpClient = new FTPClient(); ftpClient.connect(ftpServer); ftpClient.login(username, password); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); return ftpClient; } | FTPUploader { protected FTPClient getFTPClient(final String ftpServer, final String username, final String password) throws IOException { final FTPClient ftpClient = new FTPClient(); ftpClient.connect(ftpServer); ftpClient.login(username, password); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); return ftpClient; } } | FTPUploader { protected FTPClient getFTPClient(final String ftpServer, final String username, final String password) throws IOException { final FTPClient ftpClient = new FTPClient(); ftpClient.connect(ftpServer); ftpClient.login(username, password); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); return ftpClient; } } | FTPUploader { protected FTPClient getFTPClient(final String ftpServer, final String username, final String password) throws IOException { final FTPClient ftpClient = new FTPClient(); ftpClient.connect(ftpServer); ftpClient.login(username, password); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); return ftpClient; } void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password,
final String sourceDirectory, final String targetDirectory,
final int maxRetryCount); } | FTPUploader { protected FTPClient getFTPClient(final String ftpServer, final String username, final String password) throws IOException { final FTPClient ftpClient = new FTPClient(); ftpClient.connect(ftpServer); ftpClient.login(username, password); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); return ftpClient; } void uploadDirectoryWithRetries(final String ftpServer, final String username, final String password,
final String sourceDirectory, final String targetDirectory,
final int maxRetryCount); static final String UPLOAD_START; static final String UPLOAD_SUCCESS; static final String UPLOAD_FAILURE; static final String UPLOAD_RETRY_FAILURE; static final String UPLOAD_DIR_START; static final String UPLOAD_DIR_FINISH; static final String UPLOAD_DIR_FAILURE; static final String UPLOAD_DIR; static final String UPLOAD_FILE; static final String UPLOAD_FILE_REPLY; } |
@Test public void testParseOperationSystem() throws Exception { assertEquals(OperatingSystemEnum.Windows, Utils.parseOperationSystem("windows")); assertEquals(OperatingSystemEnum.Linux, Utils.parseOperationSystem("Linux")); assertEquals(OperatingSystemEnum.Docker, Utils.parseOperationSystem("dOcker")); } | public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } static String getArtifactCompileVersion(File artifact); static OperatingSystemEnum parseOperationSystem(final String os); static boolean isGUID(String input); static String getSegment(String id, String segment); static String getSubscriptionId(String resourceId); static boolean isPomPackagingProject(String packaging); static boolean isJarPackagingProject(String packaging); static boolean isWarPackagingProject(String packaging); } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } static String getArtifactCompileVersion(File artifact); static OperatingSystemEnum parseOperationSystem(final String os); static boolean isGUID(String input); static String getSegment(String id, String segment); static String getSubscriptionId(String resourceId); static boolean isPomPackagingProject(String packaging); static boolean isJarPackagingProject(String packaging); static boolean isWarPackagingProject(String packaging); } |
@Test public void testParseOperationSystemUnknown() throws Exception { try { Utils.parseOperationSystem("unkown"); fail("expected AzureExecutionException when os is invalid"); } catch (AzureExecutionException ex) { } try { Utils.parseOperationSystem("windows "); fail("expected AzureExecutionException when os has spaces"); } catch (AzureExecutionException ex) { } try { Utils.parseOperationSystem(" "); fail("expected AzureExecutionException when os is empty"); } catch (AzureExecutionException ex) { } try { Utils.parseOperationSystem(null); fail("expected AzureExecutionException when os is null"); } catch (AzureExecutionException ex) { } } | public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } static String getArtifactCompileVersion(File artifact); static OperatingSystemEnum parseOperationSystem(final String os); static boolean isGUID(String input); static String getSegment(String id, String segment); static String getSubscriptionId(String resourceId); static boolean isPomPackagingProject(String packaging); static boolean isJarPackagingProject(String packaging); static boolean isWarPackagingProject(String packaging); } | Utils { public static OperatingSystemEnum parseOperationSystem(final String os) throws AzureExecutionException { if (StringUtils.isEmpty(os)) { throw new AzureExecutionException("The value of 'os' is empty, please specify it in 'runtime' configuration."); } switch (os.toLowerCase(Locale.ENGLISH)) { case "windows": return OperatingSystemEnum.Windows; case "linux": return OperatingSystemEnum.Linux; case "docker": return OperatingSystemEnum.Docker; default: throw new AzureExecutionException("The value of <os> is unknown, supported values are: windows, " + "linux and docker."); } } static String getArtifactCompileVersion(File artifact); static OperatingSystemEnum parseOperationSystem(final String os); static boolean isGUID(String input); static String getSegment(String id, String segment); static String getSubscriptionId(String resourceId); static boolean isPomPackagingProject(String packaging); static boolean isJarPackagingProject(String packaging); static boolean isWarPackagingProject(String packaging); } |
@Test public void getProject() throws Exception { assertEquals(project, mojo.getProject()); } | public MavenProject getProject() { return project; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenProject getProject() { return project; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenProject getProject() { return project; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenProject getProject() { return project; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenProject getProject() { return project; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test(expected = AzureExecutionException.class) public void getArtifactHandlerThrowException() throws Exception { getMojoFromPom().getArtifactHandler(); } | protected ArtifactHandler getArtifactHandler() throws AzureExecutionException { final ArtifactHandlerBase.Builder builder; final DeploymentType deploymentType = getDeploymentType(); getTelemetryProxy().addDefaultProperty(DEPLOYMENT_TYPE_KEY, deploymentType.toString()); switch (deploymentType) { case MSDEPLOY: builder = new MSDeployArtifactHandlerImpl.Builder().functionAppName(this.getAppName()); break; case FTP: builder = new FTPArtifactHandlerImpl.Builder(); break; case ZIP: builder = new ZIPArtifactHandlerImpl.Builder(); break; case RUN_FROM_BLOB: builder = new RunFromBlobArtifactHandlerImpl.Builder(); break; case DOCKER: builder = new DockerArtifactHandler.Builder(); break; case EMPTY: case RUN_FROM_ZIP: builder = new RunFromZipArtifactHandlerImpl.Builder(); break; default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } return builder.project(ProjectUtils.convertCommonProject(this.getProject())) .stagingDirectoryPath(this.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(this.getBuildDirectoryAbsolutePath()) .build(); } | DeployMojo extends AbstractFunctionMojo { protected ArtifactHandler getArtifactHandler() throws AzureExecutionException { final ArtifactHandlerBase.Builder builder; final DeploymentType deploymentType = getDeploymentType(); getTelemetryProxy().addDefaultProperty(DEPLOYMENT_TYPE_KEY, deploymentType.toString()); switch (deploymentType) { case MSDEPLOY: builder = new MSDeployArtifactHandlerImpl.Builder().functionAppName(this.getAppName()); break; case FTP: builder = new FTPArtifactHandlerImpl.Builder(); break; case ZIP: builder = new ZIPArtifactHandlerImpl.Builder(); break; case RUN_FROM_BLOB: builder = new RunFromBlobArtifactHandlerImpl.Builder(); break; case DOCKER: builder = new DockerArtifactHandler.Builder(); break; case EMPTY: case RUN_FROM_ZIP: builder = new RunFromZipArtifactHandlerImpl.Builder(); break; default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } return builder.project(ProjectUtils.convertCommonProject(this.getProject())) .stagingDirectoryPath(this.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(this.getBuildDirectoryAbsolutePath()) .build(); } } | DeployMojo extends AbstractFunctionMojo { protected ArtifactHandler getArtifactHandler() throws AzureExecutionException { final ArtifactHandlerBase.Builder builder; final DeploymentType deploymentType = getDeploymentType(); getTelemetryProxy().addDefaultProperty(DEPLOYMENT_TYPE_KEY, deploymentType.toString()); switch (deploymentType) { case MSDEPLOY: builder = new MSDeployArtifactHandlerImpl.Builder().functionAppName(this.getAppName()); break; case FTP: builder = new FTPArtifactHandlerImpl.Builder(); break; case ZIP: builder = new ZIPArtifactHandlerImpl.Builder(); break; case RUN_FROM_BLOB: builder = new RunFromBlobArtifactHandlerImpl.Builder(); break; case DOCKER: builder = new DockerArtifactHandler.Builder(); break; case EMPTY: case RUN_FROM_ZIP: builder = new RunFromZipArtifactHandlerImpl.Builder(); break; default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } return builder.project(ProjectUtils.convertCommonProject(this.getProject())) .stagingDirectoryPath(this.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(this.getBuildDirectoryAbsolutePath()) .build(); } } | DeployMojo extends AbstractFunctionMojo { protected ArtifactHandler getArtifactHandler() throws AzureExecutionException { final ArtifactHandlerBase.Builder builder; final DeploymentType deploymentType = getDeploymentType(); getTelemetryProxy().addDefaultProperty(DEPLOYMENT_TYPE_KEY, deploymentType.toString()); switch (deploymentType) { case MSDEPLOY: builder = new MSDeployArtifactHandlerImpl.Builder().functionAppName(this.getAppName()); break; case FTP: builder = new FTPArtifactHandlerImpl.Builder(); break; case ZIP: builder = new ZIPArtifactHandlerImpl.Builder(); break; case RUN_FROM_BLOB: builder = new RunFromBlobArtifactHandlerImpl.Builder(); break; case DOCKER: builder = new DockerArtifactHandler.Builder(); break; case EMPTY: case RUN_FROM_ZIP: builder = new RunFromZipArtifactHandlerImpl.Builder(); break; default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } return builder.project(ProjectUtils.convertCommonProject(this.getProject())) .stagingDirectoryPath(this.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(this.getBuildDirectoryAbsolutePath()) .build(); } @Override DeploymentType getDeploymentType(); } | DeployMojo extends AbstractFunctionMojo { protected ArtifactHandler getArtifactHandler() throws AzureExecutionException { final ArtifactHandlerBase.Builder builder; final DeploymentType deploymentType = getDeploymentType(); getTelemetryProxy().addDefaultProperty(DEPLOYMENT_TYPE_KEY, deploymentType.toString()); switch (deploymentType) { case MSDEPLOY: builder = new MSDeployArtifactHandlerImpl.Builder().functionAppName(this.getAppName()); break; case FTP: builder = new FTPArtifactHandlerImpl.Builder(); break; case ZIP: builder = new ZIPArtifactHandlerImpl.Builder(); break; case RUN_FROM_BLOB: builder = new RunFromBlobArtifactHandlerImpl.Builder(); break; case DOCKER: builder = new DockerArtifactHandler.Builder(); break; case EMPTY: case RUN_FROM_ZIP: builder = new RunFromZipArtifactHandlerImpl.Builder(); break; default: throw new AzureExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } return builder.project(ProjectUtils.convertCommonProject(this.getProject())) .stagingDirectoryPath(this.getDeploymentStagingDirectoryPath()) .buildDirectoryAbsolutePath(this.getBuildDirectoryAbsolutePath()) .build(); } @Override DeploymentType getDeploymentType(); } |
@Test public void getSession() throws Exception { assertEquals(session, mojo.getSession()); } | public MavenSession getSession() { return session; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenSession getSession() { return session; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenSession getSession() { return session; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenSession getSession() { return session; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenSession getSession() { return session; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getMavenResourcesFiltering() throws Exception { assertEquals(filtering, mojo.getMavenResourcesFiltering()); } | public MavenResourcesFiltering getMavenResourcesFiltering() { return mavenResourcesFiltering; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenResourcesFiltering getMavenResourcesFiltering() { return mavenResourcesFiltering; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenResourcesFiltering getMavenResourcesFiltering() { return mavenResourcesFiltering; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenResourcesFiltering getMavenResourcesFiltering() { return mavenResourcesFiltering; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public MavenResourcesFiltering getMavenResourcesFiltering() { return mavenResourcesFiltering; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getBuildDirectoryAbsolutePath() throws Exception { assertEquals("target", mojo.getBuildDirectoryAbsolutePath()); } | public String getBuildDirectoryAbsolutePath() { return buildDirectory.getAbsolutePath(); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public String getBuildDirectoryAbsolutePath() { return buildDirectory.getAbsolutePath(); } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public String getBuildDirectoryAbsolutePath() { return buildDirectory.getAbsolutePath(); } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public String getBuildDirectoryAbsolutePath() { return buildDirectory.getAbsolutePath(); } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public String getBuildDirectoryAbsolutePath() { return buildDirectory.getAbsolutePath(); } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getAuthenticationSetting() throws Exception { assertEquals(authenticationSetting, mojo.getAuthenticationSetting()); } | @Override public AuthenticationSetting getAuthenticationSetting() { return authentication; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public AuthenticationSetting getAuthenticationSetting() { return authentication; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public AuthenticationSetting getAuthenticationSetting() { return authentication; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public AuthenticationSetting getAuthenticationSetting() { return authentication; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public AuthenticationSetting getAuthenticationSetting() { return authentication; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getAzureClient() throws Exception { assertEquals(azure, mojo.getAzureClient()); } | public Azure getAzureClient() throws AzureAuthFailureException { if (azure == null) { if (this.authentication != null && (this.authentication.getFile() != null || StringUtils.isNotBlank(authentication.getServerId()))) { Log.warn("You are using an old way of authentication which will be deprecated in future versions, please change your configurations."); azure = new AzureAuthHelperLegacy(this).getAzureClient(); } else { initAuth(); azure = getAzureClientByAuthType(); } if (azure == null) { getTelemetryProxy().trackEvent(INIT_FAILURE); throw new AzureAuthFailureException(AZURE_INIT_FAIL); } printCurrentSubscription(azure); getTelemetryProxy().addDefaultProperty(AUTH_TYPE, authType); getTelemetryProxy().addDefaultProperty(AUTH_METHOD, getAuthMethod()); getTelemetryProxy().addDefaultProperty(SUBSCRIPTION_ID_KEY, azure.subscriptionId()); } return azure; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public Azure getAzureClient() throws AzureAuthFailureException { if (azure == null) { if (this.authentication != null && (this.authentication.getFile() != null || StringUtils.isNotBlank(authentication.getServerId()))) { Log.warn("You are using an old way of authentication which will be deprecated in future versions, please change your configurations."); azure = new AzureAuthHelperLegacy(this).getAzureClient(); } else { initAuth(); azure = getAzureClientByAuthType(); } if (azure == null) { getTelemetryProxy().trackEvent(INIT_FAILURE); throw new AzureAuthFailureException(AZURE_INIT_FAIL); } printCurrentSubscription(azure); getTelemetryProxy().addDefaultProperty(AUTH_TYPE, authType); getTelemetryProxy().addDefaultProperty(AUTH_METHOD, getAuthMethod()); getTelemetryProxy().addDefaultProperty(SUBSCRIPTION_ID_KEY, azure.subscriptionId()); } return azure; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public Azure getAzureClient() throws AzureAuthFailureException { if (azure == null) { if (this.authentication != null && (this.authentication.getFile() != null || StringUtils.isNotBlank(authentication.getServerId()))) { Log.warn("You are using an old way of authentication which will be deprecated in future versions, please change your configurations."); azure = new AzureAuthHelperLegacy(this).getAzureClient(); } else { initAuth(); azure = getAzureClientByAuthType(); } if (azure == null) { getTelemetryProxy().trackEvent(INIT_FAILURE); throw new AzureAuthFailureException(AZURE_INIT_FAIL); } printCurrentSubscription(azure); getTelemetryProxy().addDefaultProperty(AUTH_TYPE, authType); getTelemetryProxy().addDefaultProperty(AUTH_METHOD, getAuthMethod()); getTelemetryProxy().addDefaultProperty(SUBSCRIPTION_ID_KEY, azure.subscriptionId()); } return azure; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public Azure getAzureClient() throws AzureAuthFailureException { if (azure == null) { if (this.authentication != null && (this.authentication.getFile() != null || StringUtils.isNotBlank(authentication.getServerId()))) { Log.warn("You are using an old way of authentication which will be deprecated in future versions, please change your configurations."); azure = new AzureAuthHelperLegacy(this).getAzureClient(); } else { initAuth(); azure = getAzureClientByAuthType(); } if (azure == null) { getTelemetryProxy().trackEvent(INIT_FAILURE); throw new AzureAuthFailureException(AZURE_INIT_FAIL); } printCurrentSubscription(azure); getTelemetryProxy().addDefaultProperty(AUTH_TYPE, authType); getTelemetryProxy().addDefaultProperty(AUTH_METHOD, getAuthMethod()); getTelemetryProxy().addDefaultProperty(SUBSCRIPTION_ID_KEY, azure.subscriptionId()); } return azure; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public Azure getAzureClient() throws AzureAuthFailureException { if (azure == null) { if (this.authentication != null && (this.authentication.getFile() != null || StringUtils.isNotBlank(authentication.getServerId()))) { Log.warn("You are using an old way of authentication which will be deprecated in future versions, please change your configurations."); azure = new AzureAuthHelperLegacy(this).getAzureClient(); } else { initAuth(); azure = getAzureClientByAuthType(); } if (azure == null) { getTelemetryProxy().trackEvent(INIT_FAILURE); throw new AzureAuthFailureException(AZURE_INIT_FAIL); } printCurrentSubscription(azure); getTelemetryProxy().addDefaultProperty(AUTH_TYPE, authType); getTelemetryProxy().addDefaultProperty(AUTH_METHOD, getAuthMethod()); getTelemetryProxy().addDefaultProperty(SUBSCRIPTION_ID_KEY, azure.subscriptionId()); } return azure; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getMavenSettings() { assertEquals(settings, mojo.getSettings()); } | @Override public Settings getSettings() { return settings; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Settings getSettings() { return settings; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Settings getSettings() { return settings; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Settings getSettings() { return settings; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Settings getSettings() { return settings; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getSubscriptionId() throws Exception { assertEquals(SUBSCRIPTION_ID, mojo.getSubscriptionId()); } | @Override public String getSubscriptionId() { return subscriptionId; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public String getSubscriptionId() { return subscriptionId; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public String getSubscriptionId() { return subscriptionId; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public String getSubscriptionId() { return subscriptionId; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public String getSubscriptionId() { return subscriptionId; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getTelemetryProxy() { assertEquals(telemetryProxy, mojo.getTelemetryProxy()); } | public TelemetryProxy getTelemetryProxy() { if (telemetryProxy == null) { initTelemetry(); } return telemetryProxy; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public TelemetryProxy getTelemetryProxy() { if (telemetryProxy == null) { initTelemetry(); } return telemetryProxy; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public TelemetryProxy getTelemetryProxy() { if (telemetryProxy == null) { initTelemetry(); } return telemetryProxy; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public TelemetryProxy getTelemetryProxy() { if (telemetryProxy == null) { initTelemetry(); } return telemetryProxy; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public TelemetryProxy getTelemetryProxy() { if (telemetryProxy == null) { initTelemetry(); } return telemetryProxy; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void isTelemetryAllowed() throws Exception { assertTrue(!mojo.isTelemetryAllowed()); } | public boolean isTelemetryAllowed() { return allowTelemetry; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public boolean isTelemetryAllowed() { return allowTelemetry; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public boolean isTelemetryAllowed() { return allowTelemetry; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public boolean isTelemetryAllowed() { return allowTelemetry; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { public boolean isTelemetryAllowed() { return allowTelemetry; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void execute() throws Exception { mojo.execute(); } | @Override public void execute() throws MojoExecutionException { try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); final Properties prop = new Properties(); if (isFirstRun(prop)) { infoWithMultipleLines(PRIVACY_STATEMENT); updateConfigurationFile(prop); } if (isSkipMojo()) { Log.info("Skip execution."); trackMojoSkip(); } else { trackMojoStart(); doExecute(); trackMojoSuccess(); } } catch (Exception e) { handleException(e); } finally { try { Thread.sleep(2 * 1000); } catch (InterruptedException e) { } ApacheSenderFactory.INSTANCE.create().close(); } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public void execute() throws MojoExecutionException { try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); final Properties prop = new Properties(); if (isFirstRun(prop)) { infoWithMultipleLines(PRIVACY_STATEMENT); updateConfigurationFile(prop); } if (isSkipMojo()) { Log.info("Skip execution."); trackMojoSkip(); } else { trackMojoStart(); doExecute(); trackMojoSuccess(); } } catch (Exception e) { handleException(e); } finally { try { Thread.sleep(2 * 1000); } catch (InterruptedException e) { } ApacheSenderFactory.INSTANCE.create().close(); } } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public void execute() throws MojoExecutionException { try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); final Properties prop = new Properties(); if (isFirstRun(prop)) { infoWithMultipleLines(PRIVACY_STATEMENT); updateConfigurationFile(prop); } if (isSkipMojo()) { Log.info("Skip execution."); trackMojoSkip(); } else { trackMojoStart(); doExecute(); trackMojoSuccess(); } } catch (Exception e) { handleException(e); } finally { try { Thread.sleep(2 * 1000); } catch (InterruptedException e) { } ApacheSenderFactory.INSTANCE.create().close(); } } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public void execute() throws MojoExecutionException { try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); final Properties prop = new Properties(); if (isFirstRun(prop)) { infoWithMultipleLines(PRIVACY_STATEMENT); updateConfigurationFile(prop); } if (isSkipMojo()) { Log.info("Skip execution."); trackMojoSkip(); } else { trackMojoStart(); doExecute(); trackMojoSuccess(); } } catch (Exception e) { handleException(e); } finally { try { Thread.sleep(2 * 1000); } catch (InterruptedException e) { } ApacheSenderFactory.INSTANCE.create().close(); } } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public void execute() throws MojoExecutionException { try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); final Properties prop = new Properties(); if (isFirstRun(prop)) { infoWithMultipleLines(PRIVACY_STATEMENT); updateConfigurationFile(prop); } if (isSkipMojo()) { Log.info("Skip execution."); trackMojoSkip(); } else { trackMojoStart(); doExecute(); trackMojoSuccess(); } } catch (Exception e) { handleException(e); } finally { try { Thread.sleep(2 * 1000); } catch (InterruptedException e) { } ApacheSenderFactory.INSTANCE.create().close(); } } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void testGetDeploymentTypeByRuntime() throws AzureExecutionException { doReturn(Windows).when(mojoSpy).getOsEnum(); assertEquals(RUN_FROM_ZIP, mojoSpy.getDeploymentTypeByRuntime()); doReturn(Linux).when(mojoSpy).getOsEnum(); doReturn(true).when(mojoSpy).isDedicatedPricingTier(); assertEquals(RUN_FROM_ZIP, mojoSpy.getDeploymentTypeByRuntime()); doReturn(false).when(mojoSpy).isDedicatedPricingTier(); assertEquals(RUN_FROM_BLOB, mojoSpy.getDeploymentTypeByRuntime()); doReturn(Docker).when(mojoSpy).getOsEnum(); assertEquals(DOCKER, mojoSpy.getDeploymentTypeByRuntime()); } | protected DeploymentType getDeploymentTypeByRuntime() throws AzureExecutionException { final OperatingSystemEnum operatingSystemEnum = getOsEnum(); switch (operatingSystemEnum) { case Docker: return DOCKER; case Linux: return isDedicatedPricingTier() ? RUN_FROM_ZIP : RUN_FROM_BLOB; default: return RUN_FROM_ZIP; } } | DeployMojo extends AbstractFunctionMojo { protected DeploymentType getDeploymentTypeByRuntime() throws AzureExecutionException { final OperatingSystemEnum operatingSystemEnum = getOsEnum(); switch (operatingSystemEnum) { case Docker: return DOCKER; case Linux: return isDedicatedPricingTier() ? RUN_FROM_ZIP : RUN_FROM_BLOB; default: return RUN_FROM_ZIP; } } } | DeployMojo extends AbstractFunctionMojo { protected DeploymentType getDeploymentTypeByRuntime() throws AzureExecutionException { final OperatingSystemEnum operatingSystemEnum = getOsEnum(); switch (operatingSystemEnum) { case Docker: return DOCKER; case Linux: return isDedicatedPricingTier() ? RUN_FROM_ZIP : RUN_FROM_BLOB; default: return RUN_FROM_ZIP; } } } | DeployMojo extends AbstractFunctionMojo { protected DeploymentType getDeploymentTypeByRuntime() throws AzureExecutionException { final OperatingSystemEnum operatingSystemEnum = getOsEnum(); switch (operatingSystemEnum) { case Docker: return DOCKER; case Linux: return isDedicatedPricingTier() ? RUN_FROM_ZIP : RUN_FROM_BLOB; default: return RUN_FROM_ZIP; } } @Override DeploymentType getDeploymentType(); } | DeployMojo extends AbstractFunctionMojo { protected DeploymentType getDeploymentTypeByRuntime() throws AzureExecutionException { final OperatingSystemEnum operatingSystemEnum = getOsEnum(); switch (operatingSystemEnum) { case Docker: return DOCKER; case Linux: return isDedicatedPricingTier() ? RUN_FROM_ZIP : RUN_FROM_BLOB; default: return RUN_FROM_ZIP; } } @Override DeploymentType getDeploymentType(); } |
@Test public void testPluginConfigurationFromPluginManagement() throws Exception { final File pom = new File(this.getClass().getClassLoader().getResource("pom-2.xml").getFile()); final Model model = TestHelper.readMavenModel(pom); final MavenProject project = Mockito.mock(MavenProject.class); Mockito.when(project.getModel()).thenReturn(model); final Xpp3Dom config = MavenUtils.getPluginConfiguration(project, "com.microsoft.azure:azure-spring-cloud-maven-plugin"); assertNotNull(config); assertNotNull(config.getChild("public")); assertEquals("false", config.getChild("public").getValue()); assertNotNull(config.getChild("deployment")); assertEquals("2", config.getChild("deployment").getChild("cpu").getValue()); } | public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } | MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } } | MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } private MavenUtils(); } | MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } private MavenUtils(); static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey); } | MavenUtils { public static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey) { final Plugin plugin = getPluginFromMavenModel(mavenProject.getModel(), pluginKey); return plugin == null ? null : (Xpp3Dom) plugin.getConfiguration(); } private MavenUtils(); static Xpp3Dom getPluginConfiguration(MavenProject mavenProject, String pluginKey); } |
@Test public void processException() throws Exception { final String message = "test exception message"; String actualMessage = null; try { mojo.handleException(new Exception(message)); } catch (Exception e) { actualMessage = e.getMessage(); } assertEquals(message, actualMessage); } | protected void handleException(final Exception exception) throws MojoExecutionException { String message = exception.getMessage(); if (StringUtils.isEmpty(message)) { message = exception.toString(); } trackMojoFailure(message); if (isFailingOnError()) { throw new MojoExecutionException(message, exception); } else { Log.error(message); } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { protected void handleException(final Exception exception) throws MojoExecutionException { String message = exception.getMessage(); if (StringUtils.isEmpty(message)) { message = exception.toString(); } trackMojoFailure(message); if (isFailingOnError()) { throw new MojoExecutionException(message, exception); } else { Log.error(message); } } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { protected void handleException(final Exception exception) throws MojoExecutionException { String message = exception.getMessage(); if (StringUtils.isEmpty(message)) { message = exception.toString(); } trackMojoFailure(message); if (isFailingOnError()) { throw new MojoExecutionException(message, exception); } else { Log.error(message); } } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { protected void handleException(final Exception exception) throws MojoExecutionException { String message = exception.getMessage(); if (StringUtils.isEmpty(message)) { message = exception.toString(); } trackMojoFailure(message); if (isFailingOnError()) { throw new MojoExecutionException(message, exception); } else { Log.error(message); } } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { protected void handleException(final Exception exception) throws MojoExecutionException { String message = exception.getMessage(); if (StringUtils.isEmpty(message)) { message = exception.toString(); } trackMojoFailure(message); if (isFailingOnError()) { throw new MojoExecutionException(message, exception); } else { Log.error(message); } } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void getTelemetryProperties() throws Exception { final Map map = mojo.getTelemetryProperties(); assertEquals(5, map.size()); assertTrue(map.containsKey(INSTALLATION_ID_KEY)); assertTrue(map.containsKey(PLUGIN_NAME_KEY)); assertTrue(map.containsKey(PLUGIN_VERSION_KEY)); assertTrue(map.containsKey(SUBSCRIPTION_ID_KEY)); assertTrue(map.containsKey(SESSION_ID_KEY)); } | @Override public Map<String, String> getTelemetryProperties() { final Map<String, String> map = new HashMap<>(); map.put(INSTALLATION_ID_KEY, getInstallationId()); map.put(PLUGIN_NAME_KEY, getPluginName()); map.put(PLUGIN_VERSION_KEY, getPluginVersion()); map.put(SUBSCRIPTION_ID_KEY, getSubscriptionId()); map.put(SESSION_ID_KEY, getSessionId()); return map; } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Map<String, String> getTelemetryProperties() { final Map<String, String> map = new HashMap<>(); map.put(INSTALLATION_ID_KEY, getInstallationId()); map.put(PLUGIN_NAME_KEY, getPluginName()); map.put(PLUGIN_VERSION_KEY, getPluginVersion()); map.put(SUBSCRIPTION_ID_KEY, getSubscriptionId()); map.put(SESSION_ID_KEY, getSessionId()); return map; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Map<String, String> getTelemetryProperties() { final Map<String, String> map = new HashMap<>(); map.put(INSTALLATION_ID_KEY, getInstallationId()); map.put(PLUGIN_NAME_KEY, getPluginName()); map.put(PLUGIN_VERSION_KEY, getPluginVersion()); map.put(SUBSCRIPTION_ID_KEY, getSubscriptionId()); map.put(SESSION_ID_KEY, getSessionId()); return map; } } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Map<String, String> getTelemetryProperties() { final Map<String, String> map = new HashMap<>(); map.put(INSTALLATION_ID_KEY, getInstallationId()); map.put(PLUGIN_NAME_KEY, getPluginName()); map.put(PLUGIN_VERSION_KEY, getPluginVersion()); map.put(SUBSCRIPTION_ID_KEY, getSubscriptionId()); map.put(SESSION_ID_KEY, getSessionId()); return map; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); } | AbstractAzureMojo extends AbstractMojo implements TelemetryConfiguration, AuthConfiguration { @Override public Map<String, String> getTelemetryProperties() { final Map<String, String> map = new HashMap<>(); map.put(INSTALLATION_ID_KEY, getInstallationId()); map.put(PLUGIN_NAME_KEY, getPluginName()); map.put(PLUGIN_VERSION_KEY, getPluginVersion()); map.put(SUBSCRIPTION_ID_KEY, getSubscriptionId()); map.put(SESSION_ID_KEY, getSessionId()); return map; } MavenProject getProject(); MavenSession getSession(); String getBuildDirectoryAbsolutePath(); MavenResourcesFiltering getMavenResourcesFiltering(); @Override Settings getSettings(); @Override AuthenticationSetting getAuthenticationSetting(); @Override String getSubscriptionId(); boolean isTelemetryAllowed(); boolean isFailingOnError(); String getSessionId(); String getInstallationId(); String getPluginName(); String getPluginVersion(); @Override String getUserAgent(); @Override String getHttpProxyHost(); @Override int getHttpProxyPort(); Azure getAzureClient(); TelemetryProxy getTelemetryProxy(); @Override Map<String, String> getTelemetryProperties(); String getAuthMethod(); @Override void execute(); void infoWithMultipleLines(final String messages); static final String PLUGIN_NAME_KEY; static final String PLUGIN_VERSION_KEY; static final String INSTALLATION_ID_KEY; static final String SESSION_ID_KEY; static final String SUBSCRIPTION_ID_KEY; static final String AUTH_TYPE; static final String AUTH_METHOD; static final String TELEMETRY_NOT_ALLOWED; static final String INIT_FAILURE; static final String AZURE_INIT_FAIL; static final String FAILURE_REASON; } |
@Test public void processSettings() throws Exception { final WithCreate withCreate = mock(WithCreate.class); handler.processSettings(withCreate); verify(withCreate, times(1)).withAppSettings(ArgumentMatchers.<String, String>anyMap()); } | @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } SettingsHandlerImpl(final AbstractWebAppMojo mojo); } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } SettingsHandlerImpl(final AbstractWebAppMojo mojo); @Override void processSettings(WithCreate withCreate); @Override void processSettings(Update update); } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } SettingsHandlerImpl(final AbstractWebAppMojo mojo); @Override void processSettings(WithCreate withCreate); @Override void processSettings(Update update); } |
@Test public void processSettings1() throws Exception { final Update update = mock(Update.class); handler.processSettings(update); verify(update, times(1)).withAppSettings(ArgumentMatchers.<String, String>anyMap()); } | @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } SettingsHandlerImpl(final AbstractWebAppMojo mojo); } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } SettingsHandlerImpl(final AbstractWebAppMojo mojo); @Override void processSettings(WithCreate withCreate); @Override void processSettings(Update update); } | SettingsHandlerImpl implements SettingsHandler { @Override public void processSettings(WithCreate withCreate) throws AzureExecutionException { final Map appSettings = mojo.getAppSettings(); if (appSettings != null && !appSettings.isEmpty()) { withCreate.withAppSettings(appSettings); } } SettingsHandlerImpl(final AbstractWebAppMojo mojo); @Override void processSettings(WithCreate withCreate); @Override void processSettings(Update update); } |
@Test public void createDeploymentSlotIfNotExist() throws AzureAuthFailureException, AzureExecutionException { final DeploymentSlotHandler handlerSpy = spy(handler); final DeploymentSlotSetting slotSetting = mock(DeploymentSlotSetting.class); final WebApp app = mock(WebApp.class); doReturn(app).when(mojo).getWebApp(); doReturn(slotSetting).when(mojo).getDeploymentSlotSetting(); doReturn("").when(slotSetting).getConfigurationSource(); doReturn("").when(slotSetting).getName(); doReturn(null).when(mojo).getDeploymentSlot(app, ""); doNothing().when(handlerSpy).createDeploymentSlot(app, "", ""); handlerSpy.createDeploymentSlotIfNotExist(); verify(handlerSpy, times(1)).createDeploymentSlotIfNotExist(); verify(handlerSpy, times(1)).createDeploymentSlot(app, "", ""); } | public void createDeploymentSlotIfNotExist() throws AzureExecutionException, AzureAuthFailureException { final DeploymentSlotSetting slotSetting = this.mojo.getDeploymentSlotSetting(); assureValidSlotSetting(slotSetting); final WebApp app = this.mojo.getWebApp(); final String slotName = slotSetting.getName(); if (this.mojo.getDeploymentSlot(app, slotName) == null) { createDeploymentSlot(app, slotName, slotSetting.getConfigurationSource()); } } | DeploymentSlotHandler { public void createDeploymentSlotIfNotExist() throws AzureExecutionException, AzureAuthFailureException { final DeploymentSlotSetting slotSetting = this.mojo.getDeploymentSlotSetting(); assureValidSlotSetting(slotSetting); final WebApp app = this.mojo.getWebApp(); final String slotName = slotSetting.getName(); if (this.mojo.getDeploymentSlot(app, slotName) == null) { createDeploymentSlot(app, slotName, slotSetting.getConfigurationSource()); } } } | DeploymentSlotHandler { public void createDeploymentSlotIfNotExist() throws AzureExecutionException, AzureAuthFailureException { final DeploymentSlotSetting slotSetting = this.mojo.getDeploymentSlotSetting(); assureValidSlotSetting(slotSetting); final WebApp app = this.mojo.getWebApp(); final String slotName = slotSetting.getName(); if (this.mojo.getDeploymentSlot(app, slotName) == null) { createDeploymentSlot(app, slotName, slotSetting.getConfigurationSource()); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); } | DeploymentSlotHandler { public void createDeploymentSlotIfNotExist() throws AzureExecutionException, AzureAuthFailureException { final DeploymentSlotSetting slotSetting = this.mojo.getDeploymentSlotSetting(); assureValidSlotSetting(slotSetting); final WebApp app = this.mojo.getWebApp(); final String slotName = slotSetting.getName(); if (this.mojo.getDeploymentSlot(app, slotName) == null) { createDeploymentSlot(app, slotName, slotSetting.getConfigurationSource()); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } | DeploymentSlotHandler { public void createDeploymentSlotIfNotExist() throws AzureExecutionException, AzureAuthFailureException { final DeploymentSlotSetting slotSetting = this.mojo.getDeploymentSlotSetting(); assureValidSlotSetting(slotSetting); final WebApp app = this.mojo.getWebApp(); final String slotName = slotSetting.getName(); if (this.mojo.getDeploymentSlot(app, slotName) == null) { createDeploymentSlot(app, slotName, slotSetting.getConfigurationSource()); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } |
@Test public void createDeploymentSlotFromParent() throws AzureExecutionException { final DeploymentSlotHandler handlerSpy = spy(handler); final WebApp app = mock(WebApp.class); final DeploymentSlots slots = mock(DeploymentSlots.class); final Blank stage1 = mock(Blank.class); final WithCreate withCreate = mock(WithCreate.class); doReturn(slots).when(app).deploymentSlots(); doReturn(stage1).when(slots).define("test"); doReturn(withCreate).when(stage1).withConfigurationFromParent(); handlerSpy.createDeploymentSlot(app, "test", "parent"); verify(withCreate, times(1)).create(); } | protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } |
@Test(expected = AzureExecutionException.class) public void createDeploymentSlotFromOtherDeploymentSlotThrowException() throws AzureExecutionException { final WebApp app = mock(WebApp.class); handler.createDeploymentSlot(app, "", "otherSlot"); } | protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } |
@Test(expected = AzureExecutionException.class) public void assureValidSlotNameThrowException() throws AzureExecutionException { final DeploymentSlotHandler handlerSpy = spy(handler); handlerSpy.assureValidSlotName("@#123"); } | protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } |
@Test public void assureValidSlotName() throws AzureExecutionException { final DeploymentSlotHandler handlerSpy = spy(handler); handlerSpy.assureValidSlotName("slot-Name"); verify(handlerSpy, times(1)).assureValidSlotName("slot-Name"); } | protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } | DeploymentSlotHandler { protected void assureValidSlotName(final String slotName) throws AzureExecutionException { final Pattern pattern = Pattern.compile(SLOT_NAME_PATTERN, Pattern.CASE_INSENSITIVE); if (StringUtils.isEmpty(slotName) || !pattern.matcher(slotName).matches()) { throw new AzureExecutionException(INVALID_SLOT_NAME); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } |
@Test public void createBreadNewDeploymentSlot() throws AzureExecutionException { final DeploymentSlotHandler handlerSpy = spy(handler); final WebApp app = mock(WebApp.class); final DeploymentSlots slots = mock(DeploymentSlots.class); final Blank stage1 = mock(Blank.class); final WithCreate withCreate = mock(WithCreate.class); doReturn(slots).when(app).deploymentSlots(); doReturn(stage1).when(slots).define("test"); doReturn(withCreate).when(stage1).withBrandNewConfiguration(); handlerSpy.createDeploymentSlot(app, "test", "new"); verify(withCreate, times(1)).create(); } | protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } | DeploymentSlotHandler { protected void createDeploymentSlot(final WebApp app, final String slotName, final String configurationSource) throws AzureExecutionException { assureValidSlotName(slotName); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(slotName); final ConfigurationSourceType type = ConfigurationSourceType.fromString(configurationSource); switch (type) { case NEW: Log.info(EMPTY_CONFIGURATION_SOURCE); definedSlot.withBrandNewConfiguration().create(); break; case PARENT: Log.info(DEFAULT_CONFIGURATION_SOURCE); definedSlot.withConfigurationFromParent().create(); break; case OTHERS: final DeploymentSlot configurationSourceSlot = this.mojo.getDeploymentSlot(app, configurationSource); if (configurationSourceSlot == null) { throw new AzureExecutionException(TARGET_CONFIGURATION_SOURCE_SLOT_NOT_EXIST); } Log.info(String.format(COPY_CONFIGURATION_FROM_SLOT, configurationSource)); definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); break; default: throw new AzureExecutionException(UNKNOWN_CONFIGURATION_SOURCE); } } DeploymentSlotHandler(final AbstractWebAppMojo mojo); void createDeploymentSlotIfNotExist(); } |
@Test public void testCreateDeploymentSlot() throws AzureAuthFailureException, AzureExecutionException { final FunctionDeploymentSlot slot = mock(FunctionDeploymentSlot.class); final DeploymentSlotSetting slotSetting = new DeploymentSlotSetting(); slotSetting.setName("Test"); doReturn(slotSetting).when(mojoSpy).getDeploymentSlotSetting(); final FunctionRuntimeHandler runtimeHandler = mock(FunctionRuntimeHandler.class); final FunctionDeploymentSlot.DefinitionStages.WithCreate mockWithCreate = mock(FunctionDeploymentSlot.DefinitionStages.WithCreate.class); doReturn(slot).when(mockWithCreate).create(); doReturn(mockWithCreate).when(runtimeHandler).createDeploymentSlot(any(), any()); doReturn(runtimeHandler).when(mojoSpy).getFunctionRuntimeHandler(); final ArtifactHandler artifactHandler = mock(ArtifactHandler.class); doNothing().when(artifactHandler).publish(any()); doReturn(artifactHandler).when(mojoSpy).getArtifactHandler(); final FunctionApp app = mock(FunctionApp.class); doReturn(app).when(mojoSpy).getFunctionApp(); doNothing().when(mojoSpy).parseConfiguration(); doNothing().when(mojoSpy).checkArtifactCompileVersion(); doReturn(slot).when(mojoSpy).updateDeploymentSlot(any(), any()); doCallRealMethod().when(mojoSpy).createDeploymentSlot(any(), any()); doReturn(null).when(mojoSpy).getResourcePortalUrl(any()); PowerMockito.mockStatic(FunctionUtils.class); PowerMockito.when(FunctionUtils.getFunctionDeploymentSlotByName(any(), any())).thenReturn(null); mojoSpy.doExecute(); verify(mojoSpy, times(1)).doExecute(); verify(mojoSpy, times(1)).createOrUpdateResource(); verify(mojoSpy, times(1)).createDeploymentSlot(any(), any()); verify(mojoSpy, times(1)).updateDeploymentSlot(any(), any()); verify(artifactHandler, times(1)).publish(any()); verifyNoMoreInteractions(artifactHandler); } | protected FunctionDeploymentSlot createDeploymentSlot(final FunctionApp functionApp, final FunctionRuntimeHandler runtimeHandler) throws AzureExecutionException, AzureAuthFailureException { Log.info(FUNCTION_SLOT_CREATE_START); final DeploymentSlotSetting slotSetting = getDeploymentSlotSetting(); final FunctionDeploymentSlot.DefinitionStages.WithCreate withCreate = runtimeHandler.createDeploymentSlot(functionApp, slotSetting); final FunctionDeploymentSlot result = withCreate.create(); Log.info(String.format(FUNCTION_SLOT_CREATED, result.name())); return updateDeploymentSlot(withCreate.create(), runtimeHandler); } | DeployMojo extends AbstractFunctionMojo { protected FunctionDeploymentSlot createDeploymentSlot(final FunctionApp functionApp, final FunctionRuntimeHandler runtimeHandler) throws AzureExecutionException, AzureAuthFailureException { Log.info(FUNCTION_SLOT_CREATE_START); final DeploymentSlotSetting slotSetting = getDeploymentSlotSetting(); final FunctionDeploymentSlot.DefinitionStages.WithCreate withCreate = runtimeHandler.createDeploymentSlot(functionApp, slotSetting); final FunctionDeploymentSlot result = withCreate.create(); Log.info(String.format(FUNCTION_SLOT_CREATED, result.name())); return updateDeploymentSlot(withCreate.create(), runtimeHandler); } } | DeployMojo extends AbstractFunctionMojo { protected FunctionDeploymentSlot createDeploymentSlot(final FunctionApp functionApp, final FunctionRuntimeHandler runtimeHandler) throws AzureExecutionException, AzureAuthFailureException { Log.info(FUNCTION_SLOT_CREATE_START); final DeploymentSlotSetting slotSetting = getDeploymentSlotSetting(); final FunctionDeploymentSlot.DefinitionStages.WithCreate withCreate = runtimeHandler.createDeploymentSlot(functionApp, slotSetting); final FunctionDeploymentSlot result = withCreate.create(); Log.info(String.format(FUNCTION_SLOT_CREATED, result.name())); return updateDeploymentSlot(withCreate.create(), runtimeHandler); } } | DeployMojo extends AbstractFunctionMojo { protected FunctionDeploymentSlot createDeploymentSlot(final FunctionApp functionApp, final FunctionRuntimeHandler runtimeHandler) throws AzureExecutionException, AzureAuthFailureException { Log.info(FUNCTION_SLOT_CREATE_START); final DeploymentSlotSetting slotSetting = getDeploymentSlotSetting(); final FunctionDeploymentSlot.DefinitionStages.WithCreate withCreate = runtimeHandler.createDeploymentSlot(functionApp, slotSetting); final FunctionDeploymentSlot result = withCreate.create(); Log.info(String.format(FUNCTION_SLOT_CREATED, result.name())); return updateDeploymentSlot(withCreate.create(), runtimeHandler); } @Override DeploymentType getDeploymentType(); } | DeployMojo extends AbstractFunctionMojo { protected FunctionDeploymentSlot createDeploymentSlot(final FunctionApp functionApp, final FunctionRuntimeHandler runtimeHandler) throws AzureExecutionException, AzureAuthFailureException { Log.info(FUNCTION_SLOT_CREATE_START); final DeploymentSlotSetting slotSetting = getDeploymentSlotSetting(); final FunctionDeploymentSlot.DefinitionStages.WithCreate withCreate = runtimeHandler.createDeploymentSlot(functionApp, slotSetting); final FunctionDeploymentSlot result = withCreate.create(); Log.info(String.format(FUNCTION_SLOT_CREATED, result.name())); return updateDeploymentSlot(withCreate.create(), runtimeHandler); } @Override DeploymentType getDeploymentType(); } |
@Test public void updateAppRuntimeTestV2() throws Exception { final WebApp app = mock(WebApp.class); final SiteInner siteInner = mock(SiteInner.class); doReturn(siteInner).when(app).inner(); doReturn("app,linux").when(siteInner).kind(); final WebApp.Update update = mock(WebApp.Update.class); doReturn(update).when(app).update(); doReturn(update).when(update).withBuiltInImage(RuntimeStack.TOMCAT_8_5_JRE8); doReturn(RuntimeStack.TOMCAT_8_5_JRE8).when(config).getRuntimeStack(); initHandlerV2(); assertSame(update, handler.updateAppRuntime(app)); verify(update, times(1)).withBuiltInImage(RuntimeStack.TOMCAT_8_5_JRE8); } | @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } private LinuxRuntimeHandlerImpl(final Builder builder); } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } private LinuxRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(WebApp app); } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } private LinuxRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(WebApp app); } |
@Test public void updateAppRuntimeTestV1() throws Exception { final WebApp app = mock(WebApp.class); final SiteInner siteInner = mock(SiteInner.class); doReturn("app,linux").when(siteInner).kind(); doReturn(siteInner).when(app).inner(); final Update update = mock(Update.class); doReturn(update).when(app).update(); doReturn(update).when(update).withBuiltInImage(any(RuntimeStack.class)); doReturn(RuntimeStack.TOMCAT_8_5_JRE8).when(config).getRuntimeStack(); initHandlerV1(); assertSame(update, handler.updateAppRuntime(app)); verify(update, times(1)).withBuiltInImage(any(RuntimeStack.class)); } | @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } private LinuxRuntimeHandlerImpl(final Builder builder); } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } private LinuxRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(WebApp app); } | LinuxRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withBuiltInImage(runtime); } private LinuxRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(WebApp app); } |
@Test public void updateAppRuntimeV2() throws Exception { final SiteInner siteInner = mock(SiteInner.class); doReturn("app,linux").when(siteInner).kind(); final WebApp.Update update = mock(WebApp.Update.class); final WebApp app = mock(WebApp.class); doReturn(siteInner).when(app).inner(); doReturn(update).when(app).update(); doReturn("nginx").when(config).getImage(); initHandlerV2(); handler.updateAppRuntime(app); verify(update, times(1)).withPublicDockerHubImage("nginx"); verifyNoMoreInteractions(update); } | @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } private PublicDockerHubRuntimeHandlerImpl(final PublicDockerHubRuntimeHandlerImpl.Builder builder); } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } private PublicDockerHubRuntimeHandlerImpl(final PublicDockerHubRuntimeHandlerImpl.Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } private PublicDockerHubRuntimeHandlerImpl(final PublicDockerHubRuntimeHandlerImpl.Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } |
@Test public void updateAppRuntimeV1() throws Exception { final SiteInner siteInner = mock(SiteInner.class); doReturn("app,linux").when(siteInner).kind(); final Update update = mock(Update.class); final WebApp app = mock(WebApp.class); doReturn(siteInner).when(app).inner(); doReturn(update).when(app).update(); doReturn("nginx").when(config).getImage(); initHandlerV1(); handler.updateAppRuntime(app); verify(update, times(1)).withPublicDockerHubImage(any(String.class)); verifyNoMoreInteractions(update); } | @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } private PublicDockerHubRuntimeHandlerImpl(final PublicDockerHubRuntimeHandlerImpl.Builder builder); } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } private PublicDockerHubRuntimeHandlerImpl(final PublicDockerHubRuntimeHandlerImpl.Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } | PublicDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update().withPublicDockerHubImage(image); } private PublicDockerHubRuntimeHandlerImpl(final PublicDockerHubRuntimeHandlerImpl.Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } |
@Test public void defineAppWithRuntime() throws Exception { AzureExecutionException exception = null; try { handler.defineAppWithRuntime(); } catch (AzureExecutionException e) { exception = e; } finally { assertNotNull(exception); } } | @Override public WithCreate defineAppWithRuntime() throws AzureExecutionException { throw new AzureExecutionException(NO_RUNTIME_CONFIG); } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public WithCreate defineAppWithRuntime() throws AzureExecutionException { throw new AzureExecutionException(NO_RUNTIME_CONFIG); } } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public WithCreate defineAppWithRuntime() throws AzureExecutionException { throw new AzureExecutionException(NO_RUNTIME_CONFIG); } } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public WithCreate defineAppWithRuntime() throws AzureExecutionException { throw new AzureExecutionException(NO_RUNTIME_CONFIG); } @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); @Override AppServicePlan updateAppServicePlan(final WebApp app); } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public WithCreate defineAppWithRuntime() throws AzureExecutionException { throw new AzureExecutionException(NO_RUNTIME_CONFIG); } @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); @Override AppServicePlan updateAppServicePlan(final WebApp app); static final String NO_RUNTIME_CONFIG; } |
@Test public void updateAppRuntime() { final WebApp app = mock(WebApp.class); assertNull(handler.updateAppRuntime(app)); } | @Override public Update updateAppRuntime(final WebApp app) { return null; } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public Update updateAppRuntime(final WebApp app) { return null; } } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public Update updateAppRuntime(final WebApp app) { return null; } } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public Update updateAppRuntime(final WebApp app) { return null; } @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); @Override AppServicePlan updateAppServicePlan(final WebApp app); } | NullRuntimeHandlerImpl implements RuntimeHandler<WebApp> { @Override public Update updateAppRuntime(final WebApp app) { return null; } @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); @Override AppServicePlan updateAppServicePlan(final WebApp app); static final String NO_RUNTIME_CONFIG; } |
@Test public void updateAppRuntimeV2() throws Exception { final SiteInner siteInner = mock(SiteInner.class); doReturn("app,linux").when(siteInner).kind(); final WebApp.UpdateStages.WithCredentials withCredentials = mock(WebApp.UpdateStages.WithCredentials.class); final WebApp.Update update = mock(WebApp.Update.class); doReturn(withCredentials).when(update).withPrivateRegistryImage("", ""); final WebApp app = mock(WebApp.class); doReturn(siteInner).when(app).inner(); doReturn(update).when(app).update(); final Server server = mock(Server.class); final Settings settings = mock(Settings.class); doReturn(server).when(settings).getServer(anyString()); doReturn(settings).when(config).getMavenSettings(); doReturn("").when(config).getImage(); doReturn("").when(config).getRegistryUrl(); doReturn("serverId").when(config).getServerId(); initHandlerForV2(); handler.updateAppRuntime(app); verify(update, times(1)).withPrivateRegistryImage("", ""); verify(server, times(1)).getUsername(); verify(server, times(1)).getPassword(); } | @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateRegistryRuntimeHandlerImpl(final Builder builder); } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateRegistryRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateRegistryRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } |
@Test public void updateAppRuntimeV1() throws Exception { final SiteInner siteInner = mock(SiteInner.class); doReturn("app,linux").when(siteInner).kind(); final WithCredentials withCredentials = mock(WithCredentials.class); final Update update = mock(Update.class); doReturn(withCredentials).when(update).withPrivateRegistryImage(null, null); final WebApp app = mock(WebApp.class); doReturn(siteInner).when(app).inner(); doReturn(update).when(app).update(); doReturn("serverId").when(config).getServerId(); final Server server = mock(Server.class); final Settings settings = mock(Settings.class); doReturn(server).when(settings).getServer(anyString()); doReturn(settings).when(config).getMavenSettings(); initHandlerV1(); handler.updateAppRuntime(app); verify(update, times(1)).withPrivateRegistryImage(null, null); verify(server, times(1)).getUsername(); verify(server, times(1)).getPassword(); } | @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateRegistryRuntimeHandlerImpl(final Builder builder); } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateRegistryRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } | PrivateRegistryRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateRegistryImage(image, registryUrl) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateRegistryRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } |
@Test public void updateAppRuntimeTestV1() throws Exception { final SiteInner siteInner = mock(SiteInner.class); doReturn("app").when(siteInner).kind(); final WithWebContainer withWebContainer = mock(WithWebContainer.class); final Update update = mock(Update.class); doReturn(withWebContainer).when(update).withJavaVersion(null); final WebApp app = mock(WebApp.class); doReturn(siteInner).when(app).inner(); doReturn(update).when(app).update(); doReturn(WebContainer.TOMCAT_8_5_NEWEST).when(config).getWebContainer(); initHandlerV1(); assertSame(update, handler.updateAppRuntime(app)); verify(withWebContainer, times(1)).withWebContainer(WebContainer.TOMCAT_8_5_NEWEST); verifyNoMoreInteractions(withWebContainer); } | @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } private WindowsRuntimeHandlerImpl(final WindowsRuntimeHandlerImpl.Builder builder); } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } private WindowsRuntimeHandlerImpl(final WindowsRuntimeHandlerImpl.Builder builder); @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } private WindowsRuntimeHandlerImpl(final WindowsRuntimeHandlerImpl.Builder builder); @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); } |
@Test public void updateAppRuntimeTestV2() throws Exception { final WebApp app = mock(WebApp.class); final SiteInner siteInner = mock(SiteInner.class); doReturn(siteInner).when(app).inner(); doReturn("app").when(siteInner).kind(); doReturn(WebContainer.TOMCAT_8_5_NEWEST).when(config).getWebContainer(); doReturn(JavaVersion.JAVA_8_NEWEST).when(config).getJavaVersion(); final WebAppBase.UpdateStages.WithWebContainer withWebContainer = mock(WebAppBase.UpdateStages.WithWebContainer.class); final WebApp.Update update = mock(WebApp.Update.class); doReturn(withWebContainer).when(update).withJavaVersion(JavaVersion.JAVA_8_NEWEST); doReturn(update).when(app).update(); initHandlerV2(); assertSame(update, handler.updateAppRuntime(app)); verify(withWebContainer, times(1)).withWebContainer(WebContainer.TOMCAT_8_5_NEWEST); verifyNoMoreInteractions(withWebContainer); } | @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } private WindowsRuntimeHandlerImpl(final WindowsRuntimeHandlerImpl.Builder builder); } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } private WindowsRuntimeHandlerImpl(final WindowsRuntimeHandlerImpl.Builder builder); @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); } | WindowsRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureWindowsWebApp(app); final Update update = app.update(); update.withJavaVersion(javaVersion).withWebContainer(webContainer); return update; } private WindowsRuntimeHandlerImpl(final WindowsRuntimeHandlerImpl.Builder builder); @Override WithCreate defineAppWithRuntime(); @Override Update updateAppRuntime(final WebApp app); } |
@Test public void doExecute() throws Exception { final PackageMojo mojo = getMojoFromPom(); final PackageMojo mojoSpy = spy(mojo); final Set<Method> methods = new HashSet<>(Arrays.asList(this.getClass().getMethods())); ReflectionUtils.setVariableValueInObject(mojoSpy, "finalName", "artifact-0.1.0"); doReturn(mock(AnnotationHandler.class)).when(mojoSpy).getAnnotationHandler(); doReturn(methods).when(mojoSpy).findAnnotatedMethods(any()); doReturn("target/azure-functions").when(mojoSpy).getDeploymentStagingDirectoryPath(); doReturn("target").when(mojoSpy).getBuildDirectoryAbsolutePath(); doReturn(mock(MavenProject.class)).when(mojoSpy).getProject(); doReturn(mock(MavenSession.class)).when(mojoSpy).getSession(); doReturn(false).when(mojoSpy).isInstallingExtensionNeeded(any()); doReturn(mock(MavenResourcesFiltering.class)).when(mojoSpy).getMavenResourcesFiltering(); doNothing().when(mojoSpy).copyHostJsonFile(any()); doNothing().when(mojoSpy).promptCompileInfo(); mojoSpy.doExecute(); } | @Override protected void doExecute() throws AzureExecutionException { promptCompileInfo(); final AnnotationHandler annotationHandler = getAnnotationHandler(); Set<Method> methods = null; try { methods = findAnnotatedMethods(annotationHandler); } catch (MalformedURLException e) { throw new AzureExecutionException("Invalid URL when resolving class path:" + e.getMessage(), e); } if (methods.size() == 0) { Log.info(NO_FUNCTIONS); return; } final Map<String, FunctionConfiguration> configMap = getFunctionConfigurations(annotationHandler, methods); validateFunctionConfigurations(configMap); final ObjectWriter objectWriter = getObjectWriter(); try { copyHostJsonFile(objectWriter); writeFunctionJsonFiles(objectWriter, configMap); copyJarsToStageDirectory(); } catch (IOException e) { throw new AzureExecutionException("Cannot perform IO operations due to error:" + e.getMessage(), e); } final CommandHandler commandHandler = new CommandHandlerImpl(); final FunctionCoreToolsHandler functionCoreToolsHandler = getFunctionCoreToolsHandler(commandHandler); final Set<BindingEnum> bindingClasses = this.getFunctionBindingEnums(configMap); installExtension(functionCoreToolsHandler, bindingClasses); Log.info(BUILD_SUCCESS); } | PackageMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { promptCompileInfo(); final AnnotationHandler annotationHandler = getAnnotationHandler(); Set<Method> methods = null; try { methods = findAnnotatedMethods(annotationHandler); } catch (MalformedURLException e) { throw new AzureExecutionException("Invalid URL when resolving class path:" + e.getMessage(), e); } if (methods.size() == 0) { Log.info(NO_FUNCTIONS); return; } final Map<String, FunctionConfiguration> configMap = getFunctionConfigurations(annotationHandler, methods); validateFunctionConfigurations(configMap); final ObjectWriter objectWriter = getObjectWriter(); try { copyHostJsonFile(objectWriter); writeFunctionJsonFiles(objectWriter, configMap); copyJarsToStageDirectory(); } catch (IOException e) { throw new AzureExecutionException("Cannot perform IO operations due to error:" + e.getMessage(), e); } final CommandHandler commandHandler = new CommandHandlerImpl(); final FunctionCoreToolsHandler functionCoreToolsHandler = getFunctionCoreToolsHandler(commandHandler); final Set<BindingEnum> bindingClasses = this.getFunctionBindingEnums(configMap); installExtension(functionCoreToolsHandler, bindingClasses); Log.info(BUILD_SUCCESS); } } | PackageMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { promptCompileInfo(); final AnnotationHandler annotationHandler = getAnnotationHandler(); Set<Method> methods = null; try { methods = findAnnotatedMethods(annotationHandler); } catch (MalformedURLException e) { throw new AzureExecutionException("Invalid URL when resolving class path:" + e.getMessage(), e); } if (methods.size() == 0) { Log.info(NO_FUNCTIONS); return; } final Map<String, FunctionConfiguration> configMap = getFunctionConfigurations(annotationHandler, methods); validateFunctionConfigurations(configMap); final ObjectWriter objectWriter = getObjectWriter(); try { copyHostJsonFile(objectWriter); writeFunctionJsonFiles(objectWriter, configMap); copyJarsToStageDirectory(); } catch (IOException e) { throw new AzureExecutionException("Cannot perform IO operations due to error:" + e.getMessage(), e); } final CommandHandler commandHandler = new CommandHandlerImpl(); final FunctionCoreToolsHandler functionCoreToolsHandler = getFunctionCoreToolsHandler(commandHandler); final Set<BindingEnum> bindingClasses = this.getFunctionBindingEnums(configMap); installExtension(functionCoreToolsHandler, bindingClasses); Log.info(BUILD_SUCCESS); } } | PackageMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { promptCompileInfo(); final AnnotationHandler annotationHandler = getAnnotationHandler(); Set<Method> methods = null; try { methods = findAnnotatedMethods(annotationHandler); } catch (MalformedURLException e) { throw new AzureExecutionException("Invalid URL when resolving class path:" + e.getMessage(), e); } if (methods.size() == 0) { Log.info(NO_FUNCTIONS); return; } final Map<String, FunctionConfiguration> configMap = getFunctionConfigurations(annotationHandler, methods); validateFunctionConfigurations(configMap); final ObjectWriter objectWriter = getObjectWriter(); try { copyHostJsonFile(objectWriter); writeFunctionJsonFiles(objectWriter, configMap); copyJarsToStageDirectory(); } catch (IOException e) { throw new AzureExecutionException("Cannot perform IO operations due to error:" + e.getMessage(), e); } final CommandHandler commandHandler = new CommandHandlerImpl(); final FunctionCoreToolsHandler functionCoreToolsHandler = getFunctionCoreToolsHandler(commandHandler); final Set<BindingEnum> bindingClasses = this.getFunctionBindingEnums(configMap); installExtension(functionCoreToolsHandler, bindingClasses); Log.info(BUILD_SUCCESS); } @Override List<Resource> getResources(); } | PackageMojo extends AbstractFunctionMojo { @Override protected void doExecute() throws AzureExecutionException { promptCompileInfo(); final AnnotationHandler annotationHandler = getAnnotationHandler(); Set<Method> methods = null; try { methods = findAnnotatedMethods(annotationHandler); } catch (MalformedURLException e) { throw new AzureExecutionException("Invalid URL when resolving class path:" + e.getMessage(), e); } if (methods.size() == 0) { Log.info(NO_FUNCTIONS); return; } final Map<String, FunctionConfiguration> configMap = getFunctionConfigurations(annotationHandler, methods); validateFunctionConfigurations(configMap); final ObjectWriter objectWriter = getObjectWriter(); try { copyHostJsonFile(objectWriter); writeFunctionJsonFiles(objectWriter, configMap); copyJarsToStageDirectory(); } catch (IOException e) { throw new AzureExecutionException("Cannot perform IO operations due to error:" + e.getMessage(), e); } final CommandHandler commandHandler = new CommandHandlerImpl(); final FunctionCoreToolsHandler functionCoreToolsHandler = getFunctionCoreToolsHandler(commandHandler); final Set<BindingEnum> bindingClasses = this.getFunctionBindingEnums(configMap); installExtension(functionCoreToolsHandler, bindingClasses); Log.info(BUILD_SUCCESS); } @Override List<Resource> getResources(); static final String SEARCH_FUNCTIONS; static final String FOUND_FUNCTIONS; static final String NO_FUNCTIONS; static final String GENERATE_CONFIG; static final String GENERATE_SKIP; static final String GENERATE_DONE; static final String VALIDATE_CONFIG; static final String VALIDATE_SKIP; static final String VALIDATE_DONE; static final String SAVE_HOST_JSON; static final String SAVE_FUNCTION_JSONS; static final String SAVE_SKIP; static final String SAVE_FUNCTION_JSON; static final String SAVE_SUCCESS; static final String COPY_JARS; static final String COPY_SUCCESS; static final String INSTALL_EXTENSIONS; static final String SKIP_INSTALL_EXTENSIONS_HTTP; static final String INSTALL_EXTENSIONS_FINISH; static final String BUILD_SUCCESS; static final String FUNCTION_JSON; static final String HOST_JSON; static final String EXTENSION_BUNDLE; static final String EXTENSION_BUNDLE_ID; static final String SKIP_INSTALL_EXTENSIONS_BUNDLE; } |
@Test public void updateAppRuntimeV2() throws Exception { final WebApp app = mock(WebApp.class); final SiteInner siteInner = mock(SiteInner.class); doReturn(siteInner).when(app).inner(); doReturn("app,linux").when(siteInner).kind(); final WebApp.Update update = mock(WebApp.Update.class); final WebApp.UpdateStages.WithCredentials withCredentials = mock(WebApp.UpdateStages.WithCredentials.class); doReturn(withCredentials).when(update).withPrivateDockerHubImage(""); doReturn(update).when(app).update(); final Server server = mock(Server.class); final Settings settings = mock(Settings.class); doReturn(server).when(settings).getServer(anyString()); doReturn(settings).when(config).getMavenSettings(); doReturn("").when(config).getImage(); doReturn("serverId").when(config).getServerId(); initHandlerV2(); handler.updateAppRuntime(app); verify(update, times(1)).withPrivateDockerHubImage(""); verify(server, times(1)).getUsername(); verify(server, times(1)).getPassword(); } | @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateDockerHubRuntimeHandlerImpl(final Builder builder); } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateDockerHubRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateDockerHubRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } |
@Test public void updateAppRuntimeV1() throws Exception { final WebApp app = mock(WebApp.class); final SiteInner siteInner = mock(SiteInner.class); doReturn("app,linux").when(siteInner).kind(); doReturn(siteInner).when(app).inner(); final Update update = mock(Update.class); final WithCredentials withCredentials = mock(WithCredentials.class); doReturn(withCredentials).when(update).withPrivateDockerHubImage(null); doReturn(update).when(app).update(); doReturn("serverId").when(config).getServerId(); final Server server = mock(Server.class); final Settings settings = mock(Settings.class); doReturn(server).when(settings).getServer(anyString()); doReturn(settings).when(config).getMavenSettings(); initHandlerV1(); handler.updateAppRuntime(app); verify(update, times(1)).withPrivateDockerHubImage(null); verify(server, times(1)).getUsername(); verify(server, times(1)).getPassword(); } | @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateDockerHubRuntimeHandlerImpl(final Builder builder); } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateDockerHubRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } | PrivateDockerHubRuntimeHandlerImpl extends WebAppRuntimeHandler { @Override public WebApp.Update updateAppRuntime(final WebApp app) throws AzureExecutionException { WebAppUtils.assureLinuxWebApp(app); return app.update() .withPrivateDockerHubImage(image) .withCredentials(dockerCredentialProvider.getUsername(), dockerCredentialProvider.getPassword()); } private PrivateDockerHubRuntimeHandlerImpl(final Builder builder); @Override WebApp.DefinitionStages.WithCreate defineAppWithRuntime(); @Override WebApp.Update updateAppRuntime(final WebApp app); } |
@Test(expected = AzureExecutionException.class) public void publishArtifactsViaWarDeployThrowException() throws AzureExecutionException { final DeployTarget target = mock(DeployTarget.class); final String stagingDirectoryPath = ""; final List<File> warArtifacts = null; buildHandler(); handlerSpy.publishArtifactsViaWarDeploy(target, stagingDirectoryPath, warArtifacts); } | protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } |
@Test public void publishArtifactsViaWarDeploy() throws AzureExecutionException { final WebApp app = mock(WebApp.class); final DeployTarget target = new WebAppDeployTarget(app); final String stagingDirectory = Paths.get(Paths.get("").toAbsolutePath().toString(), "maven-plugin-temp").toString(); final List<File> artifacts = new ArrayList<>(); final File artifact = new File(Paths.get(stagingDirectory, "dummypath", "dummy.war").toString()); artifacts.add(artifact); buildHandler(); doNothing().when(handlerSpy).publishWarArtifact(target, artifact, "dummypath"); handlerSpy.publishArtifactsViaWarDeploy(target, stagingDirectory, artifacts); verify(handlerSpy, times(1)). publishArtifactsViaWarDeploy(target, stagingDirectory, artifacts); verify(handlerSpy, times(1)).publishWarArtifact(target, artifact, "dummypath"); verifyNoMoreInteractions(handlerSpy); } | protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaWarDeploy(final DeployTarget target, final String stagingDirectoryPath, final List<File> warArtifacts) throws AzureExecutionException { if (warArtifacts == null || warArtifacts.size() == 0) { throw new AzureExecutionException( String.format("There is no war artifacts to deploy in staging path %s.", stagingDirectoryPath)); } for (final File warArtifact : warArtifacts) { final String contextPath = getContextPathFromFileName(stagingDirectoryPath, warArtifact.getAbsolutePath()); publishWarArtifact(target, warArtifact, contextPath); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } |
@Test public void publishArtifactsViaZipDeploy() throws AzureExecutionException { final DeployTarget target = mock(DeployTarget.class); final File zipTestDirectory = new File("src/test/resources/artifacthandlerv2"); final String stagingDirectoryPath = zipTestDirectory.getAbsolutePath(); doNothing().when(target).zipDeploy(any()); buildHandler(); doReturn(false).when(handlerSpy).isJavaSERuntime(); handlerSpy.publishArtifactsViaZipDeploy(target, stagingDirectoryPath); verify(handlerSpy, times(1)).isJavaSERuntime(); verify(handlerSpy, times(1)).publishArtifactsViaZipDeploy(target, stagingDirectoryPath); verifyNoMoreInteractions(handlerSpy); } | protected void publishArtifactsViaZipDeploy(final DeployTarget target, final String stagingDirectoryPath) throws AzureExecutionException { if (isJavaSERuntime()) { prepareJavaSERuntime(getAllArtifacts(stagingDirectoryPath)); } final File stagingDirectory = new File(stagingDirectoryPath); final File zipFile = Utils.createTempFile(stagingDirectory.getName(), ".zip"); ZipUtil.pack(stagingDirectory, zipFile); Log.info(String.format("Deploying the zip package %s...", zipFile.getName())); final boolean deploySuccess = performActionWithRetry(() -> target.zipDeploy(zipFile), MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("The zip deploy failed after %d times of retry.", MAX_RETRY_TIMES + 1)); } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaZipDeploy(final DeployTarget target, final String stagingDirectoryPath) throws AzureExecutionException { if (isJavaSERuntime()) { prepareJavaSERuntime(getAllArtifacts(stagingDirectoryPath)); } final File stagingDirectory = new File(stagingDirectoryPath); final File zipFile = Utils.createTempFile(stagingDirectory.getName(), ".zip"); ZipUtil.pack(stagingDirectory, zipFile); Log.info(String.format("Deploying the zip package %s...", zipFile.getName())); final boolean deploySuccess = performActionWithRetry(() -> target.zipDeploy(zipFile), MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("The zip deploy failed after %d times of retry.", MAX_RETRY_TIMES + 1)); } } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaZipDeploy(final DeployTarget target, final String stagingDirectoryPath) throws AzureExecutionException { if (isJavaSERuntime()) { prepareJavaSERuntime(getAllArtifacts(stagingDirectoryPath)); } final File stagingDirectory = new File(stagingDirectoryPath); final File zipFile = Utils.createTempFile(stagingDirectory.getName(), ".zip"); ZipUtil.pack(stagingDirectory, zipFile); Log.info(String.format("Deploying the zip package %s...", zipFile.getName())); final boolean deploySuccess = performActionWithRetry(() -> target.zipDeploy(zipFile), MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("The zip deploy failed after %d times of retry.", MAX_RETRY_TIMES + 1)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaZipDeploy(final DeployTarget target, final String stagingDirectoryPath) throws AzureExecutionException { if (isJavaSERuntime()) { prepareJavaSERuntime(getAllArtifacts(stagingDirectoryPath)); } final File stagingDirectory = new File(stagingDirectoryPath); final File zipFile = Utils.createTempFile(stagingDirectory.getName(), ".zip"); ZipUtil.pack(stagingDirectory, zipFile); Log.info(String.format("Deploying the zip package %s...", zipFile.getName())); final boolean deploySuccess = performActionWithRetry(() -> target.zipDeploy(zipFile), MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("The zip deploy failed after %d times of retry.", MAX_RETRY_TIMES + 1)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected void publishArtifactsViaZipDeploy(final DeployTarget target, final String stagingDirectoryPath) throws AzureExecutionException { if (isJavaSERuntime()) { prepareJavaSERuntime(getAllArtifacts(stagingDirectoryPath)); } final File stagingDirectory = new File(stagingDirectoryPath); final File zipFile = Utils.createTempFile(stagingDirectory.getName(), ".zip"); ZipUtil.pack(stagingDirectory, zipFile); Log.info(String.format("Deploying the zip package %s...", zipFile.getName())); final boolean deploySuccess = performActionWithRetry(() -> target.zipDeploy(zipFile), MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("The zip deploy failed after %d times of retry.", MAX_RETRY_TIMES + 1)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } |
@Test public void isJavaSERuntime() throws Exception { final MavenProject mavenProject = TestUtils.getSimpleMavenProjectForUnitTest(); final IProject project = ProjectUtils.convertCommonProject(mavenProject); final RuntimeSetting runtimeSetting = mock(RuntimeSetting.class); handler = new ArtifactHandlerImplV2.Builder() .stagingDirectoryPath(mojo.getDeploymentStagingDirectoryPath()) .project(project) .runtime(runtimeSetting) .build(); handlerSpy = spy(handler); doReturn(false).when(runtimeSetting).isEmpty(); doReturn(OperatingSystemEnum.Windows).when(runtimeSetting).getOsEnum(); doReturn(WebContainer.fromString("java 8")).when(runtimeSetting).getWebContainer(); assertTrue(handlerSpy.isJavaSERuntime()); FieldUtils.writeField(project, "artifactFile", Paths.get("artifactFile.war"), true); doReturn(true).when(runtimeSetting).isEmpty(); assertFalse(handlerSpy.isJavaSERuntime()); FieldUtils.writeField(project, "artifactFile", Paths.get("artifactFile.jar"), true); doReturn(true).when(runtimeSetting).isEmpty(); assertTrue(handlerSpy.isJavaSERuntime()); Mockito.reset(runtimeSetting); doReturn(false).when(runtimeSetting).isEmpty(); FieldUtils.writeField(project, "artifactFile", Paths.get("artifactFile.jar"), true); assertTrue(handlerSpy.isJavaSERuntime()); verify(runtimeSetting, times(0)).getOsEnum(); verify(runtimeSetting, times(0)).getWebContainer(); verify(runtimeSetting, times(0)).getLinuxRuntime(); } | protected boolean isJavaSERuntime() { final boolean isJarProject = project != null && project.isJarProject(); if (runtimeSetting == null || runtimeSetting.isEmpty() || isJarProject) { return isJarProject; } final String webContainer = runtimeSetting.getOsEnum() == OperatingSystemEnum.Windows ? runtimeSetting.getWebContainer().toString() : runtimeSetting.getLinuxRuntime().stack(); return StringUtils.containsIgnoreCase(webContainer, "java"); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected boolean isJavaSERuntime() { final boolean isJarProject = project != null && project.isJarProject(); if (runtimeSetting == null || runtimeSetting.isEmpty() || isJarProject) { return isJarProject; } final String webContainer = runtimeSetting.getOsEnum() == OperatingSystemEnum.Windows ? runtimeSetting.getWebContainer().toString() : runtimeSetting.getLinuxRuntime().stack(); return StringUtils.containsIgnoreCase(webContainer, "java"); } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected boolean isJavaSERuntime() { final boolean isJarProject = project != null && project.isJarProject(); if (runtimeSetting == null || runtimeSetting.isEmpty() || isJarProject) { return isJarProject; } final String webContainer = runtimeSetting.getOsEnum() == OperatingSystemEnum.Windows ? runtimeSetting.getWebContainer().toString() : runtimeSetting.getLinuxRuntime().stack(); return StringUtils.containsIgnoreCase(webContainer, "java"); } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected boolean isJavaSERuntime() { final boolean isJarProject = project != null && project.isJarProject(); if (runtimeSetting == null || runtimeSetting.isEmpty() || isJarProject) { return isJarProject; } final String webContainer = runtimeSetting.getOsEnum() == OperatingSystemEnum.Windows ? runtimeSetting.getWebContainer().toString() : runtimeSetting.getLinuxRuntime().stack(); return StringUtils.containsIgnoreCase(webContainer, "java"); } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { protected boolean isJavaSERuntime() { final boolean isJarProject = project != null && project.isJarProject(); if (runtimeSetting == null || runtimeSetting.isEmpty() || isJarProject) { return isJarProject; } final String webContainer = runtimeSetting.getOsEnum() == OperatingSystemEnum.Windows ? runtimeSetting.getWebContainer().toString() : runtimeSetting.getLinuxRuntime().stack(); return StringUtils.containsIgnoreCase(webContainer, "java"); } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } |
@Test public void publishWarArtifact() throws AzureExecutionException { final WebAppDeployTarget target = mock(WebAppDeployTarget.class); final File warArtifact = new File("D:\\temp\\dummypath"); final String contextPath = "dummy"; doNothing().when(target).warDeploy(warArtifact, contextPath); buildHandler(); handlerSpy.publishWarArtifact(target, warArtifact, contextPath); verify(handlerSpy, times(1)).publishWarArtifact(target, warArtifact, contextPath); verifyNoMoreInteractions(handlerSpy); } | public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } |
@Test(expected = AzureExecutionException.class) public void publishWarArtifactThrowException() throws AzureExecutionException { final WebAppDeployTarget target = mock(WebAppDeployTarget.class); final File warArtifact = new File("D:\\temp\\dummypath"); final String contextPath = "dummy"; doThrow(RuntimeException.class).when(target).warDeploy(warArtifact, contextPath); buildHandler(); handlerSpy.publishWarArtifact(target, warArtifact, contextPath); } | public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } | ArtifactHandlerImplV2 extends ArtifactHandlerBase { public void publishWarArtifact(final DeployTarget target, final File warArtifact, final String contextPath) throws AzureExecutionException { final Runnable executor = getRealWarDeployExecutor(target, warArtifact, contextPath); Log.info(String.format("Deploying the war file %s...", warArtifact.getName())); final boolean deploySuccess = performActionWithRetry(executor, MAX_RETRY_TIMES); if (!deploySuccess) { throw new AzureExecutionException( String.format("Failed to deploy war file after %d times of retry.", MAX_RETRY_TIMES)); } } protected ArtifactHandlerImplV2(final ArtifactHandlerImplV2.Builder builder); @Override void publish(final DeployTarget target); void publishWarArtifact(final DeployTarget target, final File warArtifact,
final String contextPath); } |
@Test public void publish() throws Exception { final File file = new File(""); final String path = ""; final WebApp appMock = mock(WebApp.class); doReturn(appMock).when(mojo).getWebApp(); doNothing().when(appMock).warDeploy(any(File.class), anyString()); buildHandler(); doReturn(file).when(handlerSpy).getWarFile(); doNothing().when(handlerSpy).assureWarFileExisted(any(File.class)); doReturn(path).when(handlerSpy).getContextPath(); handlerSpy.publish(new WebAppDeployTarget(appMock)); verify(appMock, times(1)).warDeploy(file, path); } | @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File war = getWarFile(); assureWarFileExisted(war); final Runnable warDeployExecutor = ArtifactHandlerUtils.getRealWarDeployExecutor(target, war, getContextPath()); Log.info(String.format(DEPLOY_START, target.getName())); int retryCount = 0; Log.info("Deploying the war file..."); while (retryCount < DEFAULT_MAX_RETRY_TIMES) { retryCount++; try { warDeployExecutor.run(); Log.info(String.format(DEPLOY_FINISH, target.getDefaultHostName())); return; } catch (Exception e) { Log.debug(String.format(UPLOAD_FAILURE, e.getMessage(), retryCount, DEFAULT_MAX_RETRY_TIMES)); } } throw new AzureExecutionException(String.format(DEPLOY_FAILURE, DEFAULT_MAX_RETRY_TIMES)); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File war = getWarFile(); assureWarFileExisted(war); final Runnable warDeployExecutor = ArtifactHandlerUtils.getRealWarDeployExecutor(target, war, getContextPath()); Log.info(String.format(DEPLOY_START, target.getName())); int retryCount = 0; Log.info("Deploying the war file..."); while (retryCount < DEFAULT_MAX_RETRY_TIMES) { retryCount++; try { warDeployExecutor.run(); Log.info(String.format(DEPLOY_FINISH, target.getDefaultHostName())); return; } catch (Exception e) { Log.debug(String.format(UPLOAD_FAILURE, e.getMessage(), retryCount, DEFAULT_MAX_RETRY_TIMES)); } } throw new AzureExecutionException(String.format(DEPLOY_FAILURE, DEFAULT_MAX_RETRY_TIMES)); } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File war = getWarFile(); assureWarFileExisted(war); final Runnable warDeployExecutor = ArtifactHandlerUtils.getRealWarDeployExecutor(target, war, getContextPath()); Log.info(String.format(DEPLOY_START, target.getName())); int retryCount = 0; Log.info("Deploying the war file..."); while (retryCount < DEFAULT_MAX_RETRY_TIMES) { retryCount++; try { warDeployExecutor.run(); Log.info(String.format(DEPLOY_FINISH, target.getDefaultHostName())); return; } catch (Exception e) { Log.debug(String.format(UPLOAD_FAILURE, e.getMessage(), retryCount, DEFAULT_MAX_RETRY_TIMES)); } } throw new AzureExecutionException(String.format(DEPLOY_FAILURE, DEFAULT_MAX_RETRY_TIMES)); } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File war = getWarFile(); assureWarFileExisted(war); final Runnable warDeployExecutor = ArtifactHandlerUtils.getRealWarDeployExecutor(target, war, getContextPath()); Log.info(String.format(DEPLOY_START, target.getName())); int retryCount = 0; Log.info("Deploying the war file..."); while (retryCount < DEFAULT_MAX_RETRY_TIMES) { retryCount++; try { warDeployExecutor.run(); Log.info(String.format(DEPLOY_FINISH, target.getDefaultHostName())); return; } catch (Exception e) { Log.debug(String.format(UPLOAD_FAILURE, e.getMessage(), retryCount, DEFAULT_MAX_RETRY_TIMES)); } } throw new AzureExecutionException(String.format(DEPLOY_FAILURE, DEFAULT_MAX_RETRY_TIMES)); } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { @Override public void publish(final DeployTarget target) throws AzureExecutionException { final File war = getWarFile(); assureWarFileExisted(war); final Runnable warDeployExecutor = ArtifactHandlerUtils.getRealWarDeployExecutor(target, war, getContextPath()); Log.info(String.format(DEPLOY_START, target.getName())); int retryCount = 0; Log.info("Deploying the war file..."); while (retryCount < DEFAULT_MAX_RETRY_TIMES) { retryCount++; try { warDeployExecutor.run(); Log.info(String.format(DEPLOY_FINISH, target.getDefaultHostName())); return; } catch (Exception e) { Log.debug(String.format(UPLOAD_FAILURE, e.getMessage(), retryCount, DEFAULT_MAX_RETRY_TIMES)); } } throw new AzureExecutionException(String.format(DEPLOY_FAILURE, DEFAULT_MAX_RETRY_TIMES)); } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); static final String FILE_IS_NOT_WAR; static final String FIND_WAR_FILE_FAIL; static final String UPLOAD_FAILURE; static final String DEPLOY_FAILURE; static final int DEFAULT_MAX_RETRY_TIMES; } |
@Test public void getContextPath() { doReturn("/").when(mojo).getPath(); buildHandler(); assertEquals(handlerSpy.getContextPath(), ""); doReturn(" / ").when(mojo).getPath(); buildHandler(); assertEquals(handlerSpy.getContextPath(), ""); doReturn("/test").when(mojo).getPath(); buildHandler(); assertEquals(handlerSpy.getContextPath(), "test"); doReturn("test").when(mojo).getPath(); buildHandler(); assertEquals(handlerSpy.getContextPath(), "test"); doReturn("/test/test").when(mojo).getPath(); buildHandler(); assertEquals(handlerSpy.getContextPath(), "test/test"); doReturn("test/test").when(mojo).getPath(); buildHandler(); assertEquals(handlerSpy.getContextPath(), "test/test"); } | protected String getContextPath() { String path = contextPath.trim(); if (path.charAt(0) == '/') { path = path.substring(1); } return path; } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected String getContextPath() { String path = contextPath.trim(); if (path.charAt(0) == '/') { path = path.substring(1); } return path; } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected String getContextPath() { String path = contextPath.trim(); if (path.charAt(0) == '/') { path = path.substring(1); } return path; } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected String getContextPath() { String path = contextPath.trim(); if (path.charAt(0) == '/') { path = path.substring(1); } return path; } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected String getContextPath() { String path = contextPath.trim(); if (path.charAt(0) == '/') { path = path.substring(1); } return path; } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); static final String FILE_IS_NOT_WAR; static final String FIND_WAR_FILE_FAIL; static final String UPLOAD_FAILURE; static final String DEPLOY_FAILURE; static final int DEFAULT_MAX_RETRY_TIMES; } |
@Test public void getAnnotationHandler() throws Exception { final PackageMojo mojo = getMojoFromPom(); final AnnotationHandler handler = mojo.getAnnotationHandler(); assertNotNull(handler); assertTrue(handler instanceof AnnotationHandlerImpl); } | protected AnnotationHandler getAnnotationHandler() { return new AnnotationHandlerImpl(); } | PackageMojo extends AbstractFunctionMojo { protected AnnotationHandler getAnnotationHandler() { return new AnnotationHandlerImpl(); } } | PackageMojo extends AbstractFunctionMojo { protected AnnotationHandler getAnnotationHandler() { return new AnnotationHandlerImpl(); } } | PackageMojo extends AbstractFunctionMojo { protected AnnotationHandler getAnnotationHandler() { return new AnnotationHandlerImpl(); } @Override List<Resource> getResources(); } | PackageMojo extends AbstractFunctionMojo { protected AnnotationHandler getAnnotationHandler() { return new AnnotationHandlerImpl(); } @Override List<Resource> getResources(); static final String SEARCH_FUNCTIONS; static final String FOUND_FUNCTIONS; static final String NO_FUNCTIONS; static final String GENERATE_CONFIG; static final String GENERATE_SKIP; static final String GENERATE_DONE; static final String VALIDATE_CONFIG; static final String VALIDATE_SKIP; static final String VALIDATE_DONE; static final String SAVE_HOST_JSON; static final String SAVE_FUNCTION_JSONS; static final String SAVE_SKIP; static final String SAVE_FUNCTION_JSON; static final String SAVE_SUCCESS; static final String COPY_JARS; static final String COPY_SUCCESS; static final String INSTALL_EXTENSIONS; static final String SKIP_INSTALL_EXTENSIONS_HTTP; static final String INSTALL_EXTENSIONS_FINISH; static final String BUILD_SUCCESS; static final String FUNCTION_JSON; static final String HOST_JSON; static final String EXTENSION_BUNDLE; static final String EXTENSION_BUNDLE_ID; static final String SKIP_INSTALL_EXTENSIONS_BUNDLE; } |
@Test public void getWarFile() { doReturn(null).when(mojo).getWarFile(); doReturn("buildDirectory").when(mojo).getBuildDirectoryAbsolutePath(); final MavenProject projectMock = mock(MavenProject.class); final Build buildMock = mock(Build.class); doReturn(projectMock).when(mojo).getProject(); doReturn(buildMock).when(projectMock).getBuild(); doReturn("finalName").when(buildMock).getFinalName(); doReturn("buildDirectory/finalName.war").when(mojo).getWarFile(); buildHandler(); final File customWarFile = handlerSpy.getWarFile(); assertNotNull(customWarFile); assertEquals(customWarFile.getPath(), Paths.get("buildDirectory/finalName.war").toString()); doReturn("warFile.war").when(mojo).getWarFile(); buildHandler(); final File defaultWar = handlerSpy.getWarFile(); assertNotNull(defaultWar); assertEquals(defaultWar.getPath(), Paths.get("warFile.war").toString()); } | protected File getWarFile() { return StringUtils.isNotEmpty(warFile) ? new File(warFile) : new File(project.getArtifactFile().toString()); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected File getWarFile() { return StringUtils.isNotEmpty(warFile) ? new File(warFile) : new File(project.getArtifactFile().toString()); } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected File getWarFile() { return StringUtils.isNotEmpty(warFile) ? new File(warFile) : new File(project.getArtifactFile().toString()); } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected File getWarFile() { return StringUtils.isNotEmpty(warFile) ? new File(warFile) : new File(project.getArtifactFile().toString()); } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected File getWarFile() { return StringUtils.isNotEmpty(warFile) ? new File(warFile) : new File(project.getArtifactFile().toString()); } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); static final String FILE_IS_NOT_WAR; static final String FIND_WAR_FILE_FAIL; static final String UPLOAD_FAILURE; static final String DEPLOY_FAILURE; static final int DEFAULT_MAX_RETRY_TIMES; } |
@Test(expected = AzureExecutionException.class) public void assureWarFileExistedWhenFileExtWrong() throws AzureExecutionException { buildHandler(); handlerSpy.assureWarFileExisted(new File("test.jar")); } | protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); static final String FILE_IS_NOT_WAR; static final String FIND_WAR_FILE_FAIL; static final String UPLOAD_FAILURE; static final String DEPLOY_FAILURE; static final int DEFAULT_MAX_RETRY_TIMES; } |
@Test(expected = AzureExecutionException.class) public void assureWarFileExistedWhenFileNotExist() throws AzureExecutionException { final File fileMock = mock(File.class); doReturn("test.war").when(fileMock).getName(); doReturn(false).when(fileMock).exists(); buildHandler(); handlerSpy.assureWarFileExisted(fileMock); } | protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); static final String FILE_IS_NOT_WAR; static final String FIND_WAR_FILE_FAIL; static final String UPLOAD_FAILURE; static final String DEPLOY_FAILURE; static final int DEFAULT_MAX_RETRY_TIMES; } |
@Test(expected = AzureExecutionException.class) public void assureWarFileExistedWhenIsNotAFile() throws AzureExecutionException { final File fileMock = mock(File.class); doReturn("test.war").when(fileMock).getName(); doReturn(false).when(fileMock).exists(); doReturn(false).when(fileMock).isFile(); buildHandler(); handlerSpy.assureWarFileExisted(fileMock); } | protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); static final String FILE_IS_NOT_WAR; static final String FIND_WAR_FILE_FAIL; static final String UPLOAD_FAILURE; static final String DEPLOY_FAILURE; static final int DEFAULT_MAX_RETRY_TIMES; } |
@Test public void assureWarFileExisted() throws AzureExecutionException { final File file = mock(File.class); doReturn("test.war").when(file).getName(); doReturn(true).when(file).exists(); doReturn(true).when(file).isFile(); buildHandler(); handlerSpy.assureWarFileExisted(file); verify(file).getName(); verify(file).exists(); verify(file).isFile(); } | protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); } | WarArtifactHandlerImpl extends ArtifactHandlerBase { protected void assureWarFileExisted(final File war) throws AzureExecutionException { if (!Files.getFileExtension(war.getName()).equalsIgnoreCase("war")) { throw new AzureExecutionException(FILE_IS_NOT_WAR); } if (!war.exists() || !war.isFile()) { throw new AzureExecutionException(String.format(FIND_WAR_FILE_FAIL, war.getAbsolutePath())); } } protected WarArtifactHandlerImpl(final WarArtifactHandlerImpl.Builder builder); @Override void publish(final DeployTarget target); static final String FILE_IS_NOT_WAR; static final String FIND_WAR_FILE_FAIL; static final String UPLOAD_FAILURE; static final String DEPLOY_FAILURE; static final int DEFAULT_MAX_RETRY_TIMES; } |
@Test public void publish() throws Exception { final DeployTarget deployTarget = new WebAppDeployTarget(this.mojo.getWebApp()); buildHandler(); doNothing().when(handlerSpy).publish(deployTarget); handlerSpy.publish(deployTarget); verify(handlerSpy).publish(deployTarget); } | @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test public void publishToDeploymentSlot() throws Exception { final DeploymentSlot slot = mock(DeploymentSlot.class); final DeployTarget deployTarget = new DeploymentSlotDeployTarget(slot); buildHandler(); doNothing().when(handlerSpy).publish(deployTarget); handlerSpy.publish(deployTarget); verify(handlerSpy).publish(deployTarget); } | @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { @Override public void publish(DeployTarget deployTarget) throws AzureExecutionException { final File jar = getJarFile(); assureJarFileExisted(jar); try { prepareDeploymentFiles(jar); } catch (IOException e) { throw new AzureExecutionException( String.format("Cannot copy jar to staging directory: '%s'", jar), e); } super.publish(deployTarget); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test public void prepareDeploymentFiles() throws IOException { } | protected void prepareDeploymentFiles(File jar) throws IOException { final File parent = new File(stagingDirectoryPath); parent.mkdirs(); Files.copy(jar, new File(parent, DEFAULT_APP_SERVICE_JAR_NAME)); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void prepareDeploymentFiles(File jar) throws IOException { final File parent = new File(stagingDirectoryPath); parent.mkdirs(); Files.copy(jar, new File(parent, DEFAULT_APP_SERVICE_JAR_NAME)); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void prepareDeploymentFiles(File jar) throws IOException { final File parent = new File(stagingDirectoryPath); parent.mkdirs(); Files.copy(jar, new File(parent, DEFAULT_APP_SERVICE_JAR_NAME)); } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void prepareDeploymentFiles(File jar) throws IOException { final File parent = new File(stagingDirectoryPath); parent.mkdirs(); Files.copy(jar, new File(parent, DEFAULT_APP_SERVICE_JAR_NAME)); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void prepareDeploymentFiles(File jar) throws IOException { final File parent = new File(stagingDirectoryPath); parent.mkdirs(); Files.copy(jar, new File(parent, DEFAULT_APP_SERVICE_JAR_NAME)); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test public void getJarFile() { doReturn("test.jar").when(mojo).getJarFile(); buildHandler(); assertEquals("test.jar", handlerSpy.getJarFile().getName()); final MavenProject project = mock(MavenProject.class); doReturn(project).when(mojo).getProject(); buildHandler(); assertEquals("test.jar", handlerSpy.getJarFile().getName()); assertEquals("test.jar", handlerSpy.getJarFile().getName()); } | protected File getJarFile() { final String jarFilePath = StringUtils.isNotEmpty(jarFile) ? jarFile : project.getArtifactFile().toString(); return new File(jarFilePath); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected File getJarFile() { final String jarFilePath = StringUtils.isNotEmpty(jarFile) ? jarFile : project.getArtifactFile().toString(); return new File(jarFilePath); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected File getJarFile() { final String jarFilePath = StringUtils.isNotEmpty(jarFile) ? jarFile : project.getArtifactFile().toString(); return new File(jarFilePath); } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected File getJarFile() { final String jarFilePath = StringUtils.isNotEmpty(jarFile) ? jarFile : project.getArtifactFile().toString(); return new File(jarFilePath); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected File getJarFile() { final String jarFilePath = StringUtils.isNotEmpty(jarFile) ? jarFile : project.getArtifactFile().toString(); return new File(jarFilePath); } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test(expected = AzureExecutionException.class) public void assureJarFileExistedWhenFileExtWrong() throws AzureExecutionException { buildHandler(); handlerSpy.assureJarFileExisted(new File("test.jar")); } | protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test public void getScriptFilePath() throws Exception { final PackageMojo mojo = getMojoFromPom(); final PackageMojo mojoSpy = spy(mojo); ReflectionUtils.setVariableValueInObject(mojoSpy, "finalName", "artifact-0.1.0"); final String finalName = mojoSpy.getScriptFilePath(); assertEquals("../artifact-0.1.0.jar", finalName); } | protected String getScriptFilePath() { return new StringBuilder() .append("..") .append("/") .append(getFinalName()) .append(".jar") .toString(); } | PackageMojo extends AbstractFunctionMojo { protected String getScriptFilePath() { return new StringBuilder() .append("..") .append("/") .append(getFinalName()) .append(".jar") .toString(); } } | PackageMojo extends AbstractFunctionMojo { protected String getScriptFilePath() { return new StringBuilder() .append("..") .append("/") .append(getFinalName()) .append(".jar") .toString(); } } | PackageMojo extends AbstractFunctionMojo { protected String getScriptFilePath() { return new StringBuilder() .append("..") .append("/") .append(getFinalName()) .append(".jar") .toString(); } @Override List<Resource> getResources(); } | PackageMojo extends AbstractFunctionMojo { protected String getScriptFilePath() { return new StringBuilder() .append("..") .append("/") .append(getFinalName()) .append(".jar") .toString(); } @Override List<Resource> getResources(); static final String SEARCH_FUNCTIONS; static final String FOUND_FUNCTIONS; static final String NO_FUNCTIONS; static final String GENERATE_CONFIG; static final String GENERATE_SKIP; static final String GENERATE_DONE; static final String VALIDATE_CONFIG; static final String VALIDATE_SKIP; static final String VALIDATE_DONE; static final String SAVE_HOST_JSON; static final String SAVE_FUNCTION_JSONS; static final String SAVE_SKIP; static final String SAVE_FUNCTION_JSON; static final String SAVE_SUCCESS; static final String COPY_JARS; static final String COPY_SUCCESS; static final String INSTALL_EXTENSIONS; static final String SKIP_INSTALL_EXTENSIONS_HTTP; static final String INSTALL_EXTENSIONS_FINISH; static final String BUILD_SUCCESS; static final String FUNCTION_JSON; static final String HOST_JSON; static final String EXTENSION_BUNDLE; static final String EXTENSION_BUNDLE_ID; static final String SKIP_INSTALL_EXTENSIONS_BUNDLE; } |
@Test(expected = AzureExecutionException.class) public void assureJarFileExistedWhenFileNotExist() throws AzureExecutionException { buildHandler(); final File fileMock = mock(File.class); doReturn("test.jar").when(fileMock).getName(); doReturn(false).when(fileMock).exists(); handlerSpy.assureJarFileExisted(fileMock); } | protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test(expected = AzureExecutionException.class) public void assureJarFileExistedWhenIsNotAFile() throws AzureExecutionException { final File fileMock = mock(File.class); doReturn("test.jar").when(fileMock).getName(); doReturn(false).when(fileMock).exists(); buildHandler(); handlerSpy.assureJarFileExisted(fileMock); } | protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test public void assureJarFileExisted() throws AzureExecutionException { final File file = mock(File.class); doReturn("test.jar").when(file).getName(); doReturn(true).when(file).exists(); doReturn(true).when(file).isFile(); buildHandler(); handlerSpy.assureJarFileExisted(file); verify(file).getName(); verify(file).exists(); verify(file).isFile(); } | protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); } | JarArtifactHandlerImpl extends ZIPArtifactHandlerImpl { protected void assureJarFileExisted(File jar) throws AzureExecutionException { if (!Files.getFileExtension(jar.getName()).equalsIgnoreCase("jar")) { throw new AzureExecutionException(FILE_IS_NOT_JAR); } if (!jar.exists() || !jar.isFile()) { throw new AzureExecutionException(String.format(FIND_JAR_FILE_FAIL, jar.getAbsolutePath())); } } protected JarArtifactHandlerImpl(final Builder builder); @Override void publish(DeployTarget deployTarget); static final String FILE_IS_NOT_JAR; static final String FIND_JAR_FILE_FAIL; } |
@Test public void getRuntimeHandler() throws AzureExecutionException { final WebAppConfiguration config = mock(WebAppConfiguration.class); final Azure azureClient = mock(Azure.class); final HandlerFactory factory = new HandlerFactoryImpl(); doReturn("").when(config).getAppName(); doReturn("").when(config).getResourceGroup(); doReturn(Region.US_EAST).when(config).getRegion(); doReturn(new PricingTier("Premium", "P1V2")).when(config).getPricingTier(); doReturn("").when(config).getServicePlanName(); doReturn("").when(config).getServicePlanResourceGroup(); doReturn(null).when(config).getOs(); RuntimeHandler handler = factory.getRuntimeHandler(config, azureClient); assertTrue(handler instanceof NullRuntimeHandlerImpl); doReturn(OperatingSystemEnum.Windows).when(config).getOs(); doReturn(JavaVersion.JAVA_8_NEWEST).when(config).getJavaVersion(); doReturn(WebContainer.TOMCAT_8_5_NEWEST).when(config).getWebContainer(); handler = factory.getRuntimeHandler(config, azureClient); assertTrue(handler instanceof WindowsRuntimeHandlerImpl); doReturn(OperatingSystemEnum.Linux).when(config).getOs(); doReturn(RuntimeStack.JAVA_8_JRE8).when(config).getRuntimeStack(); handler = factory.getRuntimeHandler(config, azureClient); assertTrue(handler instanceof LinuxRuntimeHandlerImpl); doReturn(OperatingSystemEnum.Docker).when(config).getOs(); doReturn("imageName").when(config).getImage(); handler = factory.getRuntimeHandler(config, azureClient); assertTrue(handler instanceof PublicDockerHubRuntimeHandlerImpl); doReturn("serverId").when(config).getServerId(); doReturn("registry").when(config).getRegistryUrl(); doReturn(mock(Settings.class)).when(config).getMavenSettings(); handler = factory.getRuntimeHandler(config, azureClient); assertTrue(handler instanceof PrivateRegistryRuntimeHandlerImpl); doReturn("").when(config).getRegistryUrl(); handler = factory.getRuntimeHandler(config, azureClient); assertTrue(handler instanceof PrivateDockerHubRuntimeHandlerImpl); doReturn("").when(config).getImage(); try { factory.getRuntimeHandler(config, azureClient); } catch (AzureExecutionException e) { assertEquals(e.getMessage(), "Invalid docker runtime configured."); } } | @Override public RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient) throws AzureExecutionException { if (config.getOs() == null) { return new NullRuntimeHandlerImpl(); } final WebAppRuntimeHandler.Builder builder; switch (config.getOs()) { case Windows: builder = new WindowsRuntimeHandlerImpl.Builder().javaVersion(config.getJavaVersion()) .webContainer(config.getWebContainer()); break; case Linux: builder = new LinuxRuntimeHandlerImpl.Builder().runtime(config.getRuntimeStack()); break; case Docker: builder = getDockerRuntimeHandlerBuilder(config); break; default: throw new AzureExecutionException("Unknown "); } return builder.appName(config.getAppName()) .resourceGroup(config.getResourceGroup()) .region(config.getRegion()) .pricingTier(config.getPricingTier()) .servicePlanName(config.getServicePlanName()) .servicePlanResourceGroup((config.getServicePlanResourceGroup())) .azure(azureClient) .build(); } | HandlerFactoryImpl extends HandlerFactory { @Override public RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient) throws AzureExecutionException { if (config.getOs() == null) { return new NullRuntimeHandlerImpl(); } final WebAppRuntimeHandler.Builder builder; switch (config.getOs()) { case Windows: builder = new WindowsRuntimeHandlerImpl.Builder().javaVersion(config.getJavaVersion()) .webContainer(config.getWebContainer()); break; case Linux: builder = new LinuxRuntimeHandlerImpl.Builder().runtime(config.getRuntimeStack()); break; case Docker: builder = getDockerRuntimeHandlerBuilder(config); break; default: throw new AzureExecutionException("Unknown "); } return builder.appName(config.getAppName()) .resourceGroup(config.getResourceGroup()) .region(config.getRegion()) .pricingTier(config.getPricingTier()) .servicePlanName(config.getServicePlanName()) .servicePlanResourceGroup((config.getServicePlanResourceGroup())) .azure(azureClient) .build(); } } | HandlerFactoryImpl extends HandlerFactory { @Override public RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient) throws AzureExecutionException { if (config.getOs() == null) { return new NullRuntimeHandlerImpl(); } final WebAppRuntimeHandler.Builder builder; switch (config.getOs()) { case Windows: builder = new WindowsRuntimeHandlerImpl.Builder().javaVersion(config.getJavaVersion()) .webContainer(config.getWebContainer()); break; case Linux: builder = new LinuxRuntimeHandlerImpl.Builder().runtime(config.getRuntimeStack()); break; case Docker: builder = getDockerRuntimeHandlerBuilder(config); break; default: throw new AzureExecutionException("Unknown "); } return builder.appName(config.getAppName()) .resourceGroup(config.getResourceGroup()) .region(config.getRegion()) .pricingTier(config.getPricingTier()) .servicePlanName(config.getServicePlanName()) .servicePlanResourceGroup((config.getServicePlanResourceGroup())) .azure(azureClient) .build(); } } | HandlerFactoryImpl extends HandlerFactory { @Override public RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient) throws AzureExecutionException { if (config.getOs() == null) { return new NullRuntimeHandlerImpl(); } final WebAppRuntimeHandler.Builder builder; switch (config.getOs()) { case Windows: builder = new WindowsRuntimeHandlerImpl.Builder().javaVersion(config.getJavaVersion()) .webContainer(config.getWebContainer()); break; case Linux: builder = new LinuxRuntimeHandlerImpl.Builder().runtime(config.getRuntimeStack()); break; case Docker: builder = getDockerRuntimeHandlerBuilder(config); break; default: throw new AzureExecutionException("Unknown "); } return builder.appName(config.getAppName()) .resourceGroup(config.getResourceGroup()) .region(config.getRegion()) .pricingTier(config.getPricingTier()) .servicePlanName(config.getServicePlanName()) .servicePlanResourceGroup((config.getServicePlanResourceGroup())) .azure(azureClient) .build(); } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); } | HandlerFactoryImpl extends HandlerFactory { @Override public RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient) throws AzureExecutionException { if (config.getOs() == null) { return new NullRuntimeHandlerImpl(); } final WebAppRuntimeHandler.Builder builder; switch (config.getOs()) { case Windows: builder = new WindowsRuntimeHandlerImpl.Builder().javaVersion(config.getJavaVersion()) .webContainer(config.getWebContainer()); break; case Linux: builder = new LinuxRuntimeHandlerImpl.Builder().runtime(config.getRuntimeStack()); break; case Docker: builder = getDockerRuntimeHandlerBuilder(config); break; default: throw new AzureExecutionException("Unknown "); } return builder.appName(config.getAppName()) .resourceGroup(config.getResourceGroup()) .region(config.getRegion()) .pricingTier(config.getPricingTier()) .servicePlanName(config.getServicePlanName()) .servicePlanResourceGroup((config.getServicePlanResourceGroup())) .azure(azureClient) .build(); } @Override RuntimeHandler getRuntimeHandler(final WebAppConfiguration config, final Azure azureClient); @Override SettingsHandler getSettingsHandler(final AbstractWebAppMojo mojo); @Override ArtifactHandler getArtifactHandler(final AbstractWebAppMojo mojo); @Override DeploymentSlotHandler getDeploymentSlotHandler(AbstractWebAppMojo mojo); static final String UNKNOWN_DEPLOYMENT_TYPE; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.