Search in sources :

Example 6 with AppRawConfig

use of com.microsoft.azure.maven.springcloud.config.AppRawConfig in project azure-maven-plugins by microsoft.

the class SpringCloudAppSettingsTest method testSaveToDom4j.

@Test
public void testSaveToDom4j() {
    final AppRawConfig app = new AppRawConfig();
    app.setSubscriptionId("subscriptionId1");
    app.setClusterName("clusterName1");
    app.setAppName("appName1");
    app.setIsPublic("true");
    final Document document = DocumentHelper.createDocument();
    final Element root = document.addElement("test");
    PomUtils.updateNode(root, ConfigurationUpdater.toMap(app));
    final String xml = "<test>" + "<subscriptionId>subscriptionId1</subscriptionId>" + "<clusterName>clusterName1</clusterName>" + "<appName>appName1</appName>" + "<isPublic>true</isPublic></test>";
    assertEquals(xml, root.asXML());
    app.setIsPublic(null);
}
Also used : Element(org.dom4j.Element) AppRawConfig(com.microsoft.azure.maven.springcloud.config.AppRawConfig) Document(org.dom4j.Document) Test(org.junit.Test)

Example 7 with AppRawConfig

use of com.microsoft.azure.maven.springcloud.config.AppRawConfig in project azure-maven-plugins by microsoft.

the class SpringCloudAppSettingsTest method testSaveToDom4jNullProperty.

@Test
public void testSaveToDom4jNullProperty() {
    final AppRawConfig app = new AppRawConfig();
    app.setSubscriptionId("subscriptionId1");
    app.setClusterName("clusterName1");
    app.setAppName("appName1");
    final Document document = DocumentHelper.createDocument();
    final Element root = document.addElement("test");
    PomUtils.updateNode(root, ConfigurationUpdater.toMap(app));
    final String xml = "<test>" + "<subscriptionId>subscriptionId1</subscriptionId>" + "<clusterName>clusterName1</clusterName>" + "<appName>appName1</appName>" + "</test>";
    assertEquals(xml, root.asXML());
}
Also used : Element(org.dom4j.Element) AppRawConfig(com.microsoft.azure.maven.springcloud.config.AppRawConfig) Document(org.dom4j.Document) Test(org.junit.Test)

Example 8 with AppRawConfig

use of com.microsoft.azure.maven.springcloud.config.AppRawConfig in project azure-maven-plugins by microsoft.

the class PomUtilsTest method testSaveXmlNoBuild.

@Test
public void testSaveXmlNoBuild() throws Exception {
    final File pomFile = new File(this.getClass().getClassLoader().getResource("pom-5.xml").getFile());
    final File tempFile = Files.createTempFile("azure-spring-cloud-plugin-test", ".xml").toFile();
    FileUtils.copyFile(pomFile, tempFile);
    final Model model = TestHelper.readMavenModel(tempFile);
    final MavenProject project = mock(MavenProject.class);
    when(project.getModel()).thenReturn(model);
    when(project.getFile()).thenReturn(tempFile);
    final AppRawConfig app = new AppRawConfig();
    app.setSubscriptionId("subscriptionId1");
    app.setClusterName("clusterName1");
    app.setAppName("appName1");
    app.setIsPublic("true");
    final AppDeploymentRawConfig deploy = new AppDeploymentRawConfig();
    deploy.setCpu("1");
    deploy.setMemoryInGB("2");
    deploy.setInstanceCount("3");
    deploy.setRuntimeVersion("8");
    deploy.setJvmOptions("jvmOptions1");
    final PluginDescriptor pd = mock(PluginDescriptor.class);
    when(pd.getGroupId()).thenReturn("com.microsoft.azure");
    when(pd.getArtifactId()).thenReturn("azure-spring-cloud-maven-plugin");
    when(pd.getVersion()).thenReturn("0.1.0.SNAPSHOT");
    app.setDeployment(deploy);
    ConfigurationUpdater.updateAppConfigToPom(app, project, pd);
    final String updatedXml = String.join("\n", Files.readAllLines(tempFile.toPath(), Charset.defaultCharset()));
    assertTrue(updatedXml.contains("<maven.compiler.target>1.8\n" + "        </maven.compiler.target>"));
    assertTrue(updatedXml.contains("<configuration>\n" + "                    <subscriptionId>subscriptionId1</subscriptionId>\n" + "                    <clusterName>clusterName1</clusterName>\n" + "                    <appName>appName1</appName>\n" + "                    <isPublic>true</isPublic>\n" + "                    <deployment>\n" + "                        <cpu>1</cpu>\n" + "                        <memoryInGB>2</memoryInGB>\n" + "                        <instanceCount>3</instanceCount>\n" + "                        <jvmOptions>jvmOptions1</jvmOptions>\n" + "                        <runtimeVersion>8</runtimeVersion>\n" + "                        <resources>\n" + "                            <resource>\n" + "                                <filtering/>\n" + "                                <mergeId/>\n" + "                                <targetPath/>\n" + "                                <directory>${project.basedir}/target</directory>\n" + "                                <includes>\n" + "                                    <include>*.jar</include>\n" + "                                </includes>\n" + "                            </resource>\n" + "                        </resources>\n" + "                    </deployment>\n" + "                </configuration>"));
    tempFile.delete();
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenProject(org.apache.maven.project.MavenProject) AppDeploymentRawConfig(com.microsoft.azure.maven.springcloud.config.AppDeploymentRawConfig) Model(org.apache.maven.model.Model) AppRawConfig(com.microsoft.azure.maven.springcloud.config.AppRawConfig) File(java.io.File) Test(org.junit.Test)

Example 9 with AppRawConfig

use of com.microsoft.azure.maven.springcloud.config.AppRawConfig in project azure-maven-plugins by microsoft.

the class PomUtilsTest method testSaveXml.

@Test
public void testSaveXml() throws Exception {
    final File pomFile = new File(this.getClass().getClassLoader().getResource("pom-4.xml").getFile());
    final File tempFile = Files.createTempFile("azure-spring-cloud-plugin-test", ".xml").toFile();
    FileUtils.copyFile(pomFile, tempFile);
    final Model model = TestHelper.readMavenModel(tempFile);
    final MavenProject project = mock(MavenProject.class);
    when(project.getModel()).thenReturn(model);
    when(project.getFile()).thenReturn(tempFile);
    final AppRawConfig app = new AppRawConfig();
    app.setSubscriptionId("subscriptionId1");
    app.setClusterName("clusterName1");
    app.setAppName("appName1");
    app.setIsPublic("true");
    final AppDeploymentRawConfig deploy = new AppDeploymentRawConfig();
    deploy.setCpu("1");
    deploy.setMemoryInGB("2");
    deploy.setInstanceCount("3");
    deploy.setRuntimeVersion("8");
    deploy.setJvmOptions("jvmOptions1");
    final Plugin plugin = model.getBuild().getPlugins().get(0);
    final PluginDescriptor pd = mock(PluginDescriptor.class);
    when(pd.getGroupId()).thenReturn(plugin.getGroupId());
    when(pd.getArtifactId()).thenReturn(plugin.getArtifactId());
    when(pd.getVersion()).thenReturn(plugin.getVersion());
    app.setDeployment(deploy);
    ConfigurationUpdater.updateAppConfigToPom(app, project, pd);
    final String updatedXml = String.join("\n", Files.readAllLines(tempFile.toPath(), Charset.defaultCharset()));
    assertTrue(updatedXml.contains("<maven.compiler.target>1.8\n" + "        </maven.compiler.target>"));
    assertTrue(updatedXml.contains("<configuration>\n" + "                    <subscriptionId>subscriptionId1</subscriptionId>\n" + "                    <clusterName>clusterName1</clusterName>\n" + "                    <appName>appName1</appName>\n" + "                    <isPublic>true</isPublic>\n" + "                    <deployment>\n" + "                        <cpu>1</cpu>\n" + "                        <memoryInGB>2</memoryInGB>\n" + "                        <instanceCount>3</instanceCount>\n" + "                        <jvmOptions>jvmOptions1</jvmOptions>\n" + "                        <runtimeVersion>8</runtimeVersion>\n" + "                        <resources>\n" + "                            <resource>\n" + "                                <filtering/>\n" + "                                <mergeId/>\n" + "                                <targetPath/>\n" + "                                <directory>${project.basedir}/target</directory>\n" + "                                <includes>\n" + "                                    <include>*.jar</include>\n" + "                                </includes>\n" + "                            </resource>\n" + "                        </resources>\n" + "                    </deployment>\n" + "                </configuration>"));
    tempFile.delete();
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenProject(org.apache.maven.project.MavenProject) AppDeploymentRawConfig(com.microsoft.azure.maven.springcloud.config.AppDeploymentRawConfig) Model(org.apache.maven.model.Model) AppRawConfig(com.microsoft.azure.maven.springcloud.config.AppRawConfig) File(java.io.File) Plugin(org.apache.maven.model.Plugin) Test(org.junit.Test)

Aggregations

AppRawConfig (com.microsoft.azure.maven.springcloud.config.AppRawConfig)9 Test (org.junit.Test)8 AppDeploymentRawConfig (com.microsoft.azure.maven.springcloud.config.AppDeploymentRawConfig)3 File (java.io.File)2 Model (org.apache.maven.model.Model)2 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)2 MavenProject (org.apache.maven.project.MavenProject)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 MavenDecryptException (com.microsoft.azure.maven.exception.MavenDecryptException)1 ConfigurationPrompter (com.microsoft.azure.maven.springcloud.config.ConfigurationPrompter)1 LoginFailureException (com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException)1 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)1 InvalidConfigurationException (com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException)1 IOException (java.io.IOException)1 Plugin (org.apache.maven.model.Plugin)1 PluginParameterExpressionEvaluator (org.apache.maven.plugin.PluginParameterExpressionEvaluator)1 ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)1