This tutorial demonstrates running within Azure Web Apps.
Azure Web Apps is able to run Servlet applications. Therefore, OfficeFloor is configured as a Servlet application as follows:
<dependency> <groupId>net.officefloor.server</groupId> <artifactId>officeserver_servlet</artifactId> </dependency> <!-- Necessary for Azure logging --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> </dependency>
The following configuration deploys the application to Azure:
<plugin> <groupId>com.microsoft.azure</groupId> <artifactId>azure-webapp-maven-plugin</artifactId> <configuration> <schemaVersion>v2</schemaVersion> <resourceGroup>officefloor</resourceGroup> <appName>officefloor</appName> <region>westus</region> <pricingTier>F1</pricingTier> <authentication> <serverId>azure-auth</serverId> </authentication> <runtime> <os>Linux</os> <javaVersion>Java 11</javaVersion> <webContainer>Tomcat 9.0</webContainer> </runtime> <appSettings> <property> <name>COSMOS_URL</name> <value>${cosmos-url}</value> </property> <property> <name>COSMOS_KEY</name> <value>${cosmos-key}</value> </property> </appSettings> <deployment> <resources> <resource> <directory>${project.basedir}/target</directory> <includes> <include>*.war</include> </includes> </resource> </resources> </deployment> </configuration> </plugin>
The properties are configured in the maven settings.xml file to avoid being checked into source code management. See the Azure tutorial regarding setting up Azure and configuring the properties.
The functionality can be tested just like any other Web on OfficeFloor (WoOF) application:
@Order(1) @RegisterExtension public final CosmosDbExtension cosmosDb = new CosmosDbExtension().waitForCosmosDb(); @Order(2) @RegisterExtension public final MockWoofServerExtension server = new MockWoofServerExtension(); private @Dependency CosmosEntities entities; @Test public void ensureCreatePost() throws Exception { // Have server create the post Post post = new Post(null, "TEST"); MockWoofResponse response = this.server.send(MockWoofServer.mockJsonRequest(HttpMethod.POST, "/posts", post)); response.assertStatus(200); // Ensure post created PartitionKey partitionKey = this.entities.createPartitionKey(new Post()); Post[] created = this.entities.getContainer(Post.class).readAllItems(partitionKey, Post.class).stream() .toArray(Post[]::new); assertEquals(1, created.length, "Should only be one created post"); assertEquals("TEST", created[0].getMessage(), "Incorrect post"); }
The next tutorial covers integrating PayPal into OfficeFloor.