Commit 85420fbc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

api doc is generated for login command

parent 67b60492
......@@ -41,6 +41,7 @@
<spring-security-test.version>5.0.8.RELEASE</spring-security-test.version>
<springframework.webflow.version>2.5.1.RELEASE</springframework.webflow.version>
<springframework.boot.version>2.0.5.RELEASE</springframework.boot.version>
<spring.restdocs.version>2.0.3.RELEASE</spring.restdocs.version>
<libsbml.version>1.0</libsbml.version>
......
......@@ -105,6 +105,32 @@
<version>${springframework.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.restdocs/spring-restdocs-mockmvc -->
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>${spring.restdocs.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Log4J2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
......@@ -327,6 +353,43 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- API documentation (https://www.vojtechruzicka.com/spring-rest-docs/) -->
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.8</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<attributes>
<project-version>${project.version}</project-version>
<build-time>${maven.build.timestamp}</build-time>
</attributes>
<logHandler>
<failIf>
<severity>${apiDocSeverityFailure}</severity>
</failIf>
</logHandler>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring.restdocs.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
......
= Rest API Documentation
Piotr Gawron
v{project-version} {build-time}
:toc: left
:sectnums:
== Authentication
=== Login
Login to the system. If credentials are invalid response with 403 status code will be returned. Token will be valid for the next 120 minutes.
==== CURL sample
include::{snippets}/authentication/login/curl-request.adoc[]
==== Request Parameters
include::{snippets}/authentication/login/request-parameters.adoc[]
==== Response Fields
include::{snippets}/authentication/login/response-fields.adoc[]
==== Sample Request
include::{snippets}/authentication/login/http-request.adoc[]
==== Sample Response
include::{snippets}/authentication/login/http-response.adoc[]
......@@ -17,6 +17,7 @@ import org.apache.logging.log4j.core.LogEvent;
import org.junit.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
......@@ -53,6 +54,9 @@ import lcsb.mapviewer.web.config.SpringWebConfig;
@ContextConfiguration(classes = SpringWebConfig.class)
abstract public class ControllerIntegrationTest {
@Rule
public JUnitRestDocumentation jUnitRestDocumentation = new JUnitRestDocumentation();
protected static final String BUILT_IN_TEST_ADMIN_PASSWORD = "admin";
protected static final String BUILT_IN_TEST_ADMIN_LOGIN = "admin";
......@@ -99,6 +103,14 @@ abstract public class ControllerIntegrationTest {
mockMvc = MockMvcBuilders.webAppContextSetup(context)
.addFilter(springSecurityFilterChain)
.build();
mockMvc = MockMvcBuilders.webAppContextSetup(context)
.addFilter(springSecurityFilterChain)
.apply(org.springframework.restdocs.mockmvc.MockMvcRestDocumentation
.documentationConfiguration(this.jUnitRestDocumentation)
.uris().withHost("minerva-dev.lcsb.uni.lu").withPort(80))
.build();
executorService = Executors.newFixedThreadPool(1);
}
......
package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -115,4 +121,23 @@ public class UserControllerAnonymousIntegrationTest extends ControllerIntegratio
.andExpect(status().is4xxClientError());
}
@Test
public void testLogin() throws Exception {
RequestBuilder request = post("/api/doLogin")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content("login=" + TEST_ADMIN_LOGIN + "&password=" + TEST_ADMIN_PASSWORD);
mockMvc.perform(request)
.andDo(document("authentication/login", requestParameters(parameterWithName("login").description("login"),
parameterWithName("password").description("password")),
responseFields(
fieldWithPath("info")
.description("status message"),
fieldWithPath("login")
.description("user login"),
fieldWithPath("token")
.description("session token"))))
.andExpect(status().is2xxSuccessful());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment