Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
feat(rest): add rest docs to resource server
Browse files Browse the repository at this point in the history
- updated asciidocs
- added asciidocs plugin and maven resource plugin to pom
- changed test name classes
- added ConfigurationContext to test classes
  • Loading branch information
maierthomas committed Dec 22, 2017
1 parent 5ff8423 commit 1885a9c
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 46 deletions.
1 change: 1 addition & 0 deletions rest/authorization-server/pom.xml
Expand Up @@ -132,6 +132,7 @@
</dependencyManagement>

<build>
<finalName>resource</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down
55 changes: 55 additions & 0 deletions rest/resource-server/pom.xml
Expand Up @@ -191,6 +191,7 @@
</dependencyManagement>

<build>
<finalName>resource</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -204,6 +205,60 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<backend>html</backend>
<doctype>book</doctype>
<attributes>
<project-version>${project.version}</project-version>
</attributes>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
6 changes: 3 additions & 3 deletions rest/resource-server/src/docs/asciidoc/api-guide.adoc
Expand Up @@ -8,7 +8,7 @@
//

= sw360 REST API Guide
Kai Tödter; Version {project-version}
BETA; Version {project-version}
:doctype: book
:icons: font
:source-highlighter: highlightjs
Expand Down Expand Up @@ -94,12 +94,12 @@ include::{snippets}/should_document_headers/response-headers.adoc[]
Whenever an error response (status code >== 400) is returned, the body will contain a JSON object
that describes the problem. The error object has the following structure:

include::{snippets}/should_document_errors/response-fields.adoc[]
include::{snippets}/should_document_error_internal_error/response-fields.adoc[]

For example, a request that attempts to get a non-existent project will produce a
`500 Internal Server Error` response:

include::{snippets}/should_document_errors/http-response.adoc[]
include::{snippets}/should_document_error_internal_error/http-response.adoc[]

[[overview-hypermedia]]
=== Hypermedia
Expand Down
23 changes: 0 additions & 23 deletions rest/resource-server/src/docs/asciidoc/api.adoc

This file was deleted.

22 changes: 22 additions & 0 deletions rest/resource-server/src/docs/asciidoc/index.adoc
@@ -0,0 +1,22 @@
//
// Copyright Siemens AG, 2017. Part of the SW360 Portal Project.
//
// All rights reserved. This configuration file is provided to you under the
// terms and conditions of the Eclipse Distribution License v1.0 which
// accompanies this distribution, and is available at
// http://www.eclipse.org/org/documents/edl-v10.php
//

= SW360 REST API
BETA; Version {project-version}
:doctype: book
:icons: font
:source-highlighter: highlightjs

SW360 is the upcoming tool for our OSS management and clearing activities.
Here you find information about the REST API for SW360.
The REST API is in early stage, link:https://github.com/sw360/sw360portal[feedback/issues] is very welcome.

* link:api-guide.html[API Guide]
* link:https://github.com/sw360/sw360portal[Git Repository]
* link:https://localhost:8443/browser.html#/api[Interactive API Browser]
Expand Up @@ -50,10 +50,11 @@ public void configure(HttpSecurity http) throws Exception {
http
.httpBasic().and()
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/**").hasAuthority("READ")
.antMatchers(HttpMethod.POST, "/**").hasAuthority("WRITE")
.antMatchers(HttpMethod.PUT, "/**").hasAuthority("WRITE")
.antMatchers(HttpMethod.PATCH, "/**").hasAuthority("WRITE").and()
.antMatchers(HttpMethod.GET, "/api").permitAll()
.antMatchers(HttpMethod.GET, "/api/**").hasAuthority("READ")
.antMatchers(HttpMethod.POST, "/api/**").hasAuthority("WRITE")
.antMatchers(HttpMethod.PUT, "/api/**").hasAuthority("WRITE")
.antMatchers(HttpMethod.PATCH, "/api/**").hasAuthority("WRITE").and()
.csrf().disable();
}

Expand Down
Expand Up @@ -31,8 +31,11 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.runner.RunWith;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.util.Base64Utils;

Expand Down
Expand Up @@ -16,10 +16,13 @@
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -29,7 +32,8 @@
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyObject;

public class ComponentTest extends IntegrationTestBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class ComponentTest extends TestIntegrationBase {

@Value("${local.server.port}")
private int port;
Expand Down
Expand Up @@ -16,10 +16,13 @@
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -29,7 +32,8 @@
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyObject;

public class ProjectTest extends IntegrationTestBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class ProjectTest extends TestIntegrationBase {

@Value("${local.server.port}")
private int port;
Expand Down
Expand Up @@ -17,6 +17,8 @@
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
Expand All @@ -26,9 +28,9 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Sw360ResourceServer.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
abstract public class IntegrationTestBase {
@ContextConfiguration
abstract public class TestIntegrationBase {

public HttpHeaders getHeaders(int port) throws IOException {
ResponseEntity<String> response =
Expand Down
Expand Up @@ -14,10 +14,13 @@
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -27,7 +30,8 @@
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;

public class UserTest extends IntegrationTestBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class UserTest extends TestIntegrationBase {

@Value("${local.server.port}")
private int port;
Expand Down
Expand Up @@ -14,11 +14,14 @@
import org.eclipse.sw360.rest.resourceserver.project.Sw360ProjectService;
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyObject;
Expand All @@ -33,7 +36,8 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class ApiSpec extends RestDocsSpecBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class ApiSpecTest extends TestRestDocsSpecBase {

@Value("${sw360.test-user-id}")
private String testUserId;
Expand Down
Expand Up @@ -21,9 +21,12 @@
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.MediaTypes;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -40,7 +43,8 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class AttachmentSpec extends RestDocsSpecBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class AttachmentSpecTest extends TestRestDocsSpecBase {

@Value("${sw360.test-user-id}")
private String testUserId;
Expand Down
Expand Up @@ -18,9 +18,12 @@
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.MediaTypes;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.*;

Expand All @@ -35,7 +38,8 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class ComponentSpec extends RestDocsSpecBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class ComponentSpecTest extends TestRestDocsSpecBase {

@Value("${sw360.test-user-id}")
private String testUserId;
Expand Down
Expand Up @@ -14,9 +14,12 @@
import org.eclipse.sw360.rest.resourceserver.license.Sw360LicenseService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.MediaTypes;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,7 +33,8 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class LicenseSpec extends RestDocsSpecBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class LicenseSpecTest extends TestRestDocsSpecBase {

@Value("${sw360.test-user-id}")
private String testUserId;
Expand Down
Expand Up @@ -17,9 +17,12 @@
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.MediaTypes;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.*;

Expand All @@ -33,7 +36,8 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class ProjectSpec extends RestDocsSpecBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class ProjectSpecTest extends TestRestDocsSpecBase {

@Value("${sw360.test-user-id}")
private String testUserId;
Expand Down

0 comments on commit 1885a9c

Please sign in to comment.