// Path: subprojects/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/TestHelper.java
// public class TestHelper {
// 
//     static public void checkResponse(String responseBody, String linkRelation, int embeddedArraySize) throws IOException {
//         JsonNode responseBodyJsonNode = new ObjectMapper().readTree(responseBody);
// 
//         assertThat(responseBodyJsonNode.has("_embedded"), is(true));
// 
//         JsonNode embeddedNode = responseBodyJsonNode.get("_embedded");
//         assertThat(embeddedNode.has("sw360:" + linkRelation), is(true));
// 
//         JsonNode sw360UsersNode = embeddedNode.get("sw360:" + linkRelation);
//         assertThat(sw360UsersNode.isArray(),is(true));
//         assertThat(sw360UsersNode.size(),is(embeddedArraySize));
// 
//         assertThat(responseBodyJsonNode.has("_links"), is(true));
// 
//         JsonNode linksNode = responseBodyJsonNode.get("_links");
//         assertThat(linksNode.has("curies"), is(true));
// 
//         JsonNode curiesNode = linksNode.get("curies").get(0);
//         assertThat(curiesNode.get("href").asText(), endsWith("docs/html5/{rel}.html"));
//         assertThat(curiesNode.get("name").asText(), is("sw360"));
//         assertThat(curiesNode.get("templated").asBoolean(), is(true));
//     }
// 
//     public static String getAccessToken(MockMvc mockMvc, String username, String password) throws Exception {
//         String authorizationHeaderValue = "Basic "
//                 + new String(Base64Utils.encode("trusted-sw360-client:sw360-secret".getBytes()));
// 
//         MockHttpServletResponse response = mockMvc
//                 .perform(post("/oauth/token")
//                         .header("Authorization", authorizationHeaderValue)
//                         .contentType(MediaType.APPLICATION_FORM_URLENCODED)
//                         .param("client_id", "trusted-sw360-client")
//                         .param("client_secret", "sw360-secret")
//                         .param("username", username)
//                         .param("password", password)
//                         .param("grant_type", "password")
//                         .param("scope", "sw360.read"))
//                 .andReturn().getResponse();
// 
//         return new ObjectMapper()
//                 .readValue(response.getContentAsByteArray(), OAuthToken.class)
//                 .accessToken;
//     }
// 
// 
//     @JsonIgnoreProperties(ignoreUnknown = true)
//     private static class OAuthToken {
//         @JsonProperty("access_token")
//         public String accessToken;
//     }
// 
// }
// 
// Path: subprojects/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/license/Sw360LicenseService.java
// @Service
// @RequiredArgsConstructor(onConstructor = @__(@Autowired))
// public class Sw360LicenseService {
//     @Value("${sw360.thrift-server-url:http://localhost:8080}")
//     private String thriftServerUrl;
// 
//     public List<License> getLicenses() {
//         try {
//             LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
//             return sw360LicenseClient.getLicenseSummary();
//         } catch (TException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public License getLicenseById(String licenseId) {
//         try {
//             LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
//             // TODO Kai Tödter 2017-01-26
//             // What is the semantics of the second parameter (organization)?
//             return sw360LicenseClient.getByID(licenseId, "?");
//         } catch (TException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public License createLicense(License license, User sw360User) {
//         try {
//             LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
//             license.setId(license.getShortname());
//             List<License> licenses = sw360LicenseClient.addLicenses(Collections.singletonList(license), sw360User);
//             for(License newlicense: licenses) {
//                 if(license.getFullname().equals(newlicense.getFullname())) {
//                     return  newlicense;
//                 }
//             }
//         } catch (TException e) {
//             throw new RuntimeException(e);
//         }
//         return null;
//     }
// 
//     private LicenseService.Iface getThriftLicenseClient() throws TTransportException {
//         THttpClient thriftClient = new THttpClient(thriftServerUrl + "/licenses/thrift");
//         TProtocol protocol = new TCompactProtocol(thriftClient);
//         return new LicenseService.Client(protocol);
//     }
// }


import org.eclipse.sw360.datahandler.thrift.licenses.License;
import org.eclipse.sw360.rest.resourceserver.TestHelper;
import org.eclipse.sw360.rest.resourceserver.license.Sw360LicenseService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.MediaTypes;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.eq;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/*
 * Copyright Siemens AG, 2017. Part of the SW360 Portal Project.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.eclipse.sw360.rest.resourceserver.restdocs;




public class LicenseSpec extends RestDocsSpecBase {

    @MockBean
// Path: subprojects/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/TestHelper.java
// public class TestHelper {
// 
//     static public void checkResponse(String responseBody, String linkRelation, int embeddedArraySize) throws IOException {
//         JsonNode responseBodyJsonNode = new ObjectMapper().readTree(responseBody);
// 
//         assertThat(responseBodyJsonNode.has("_embedded"), is(true));
// 
//         JsonNode embeddedNode = responseBodyJsonNode.get("_embedded");
//         assertThat(embeddedNode.has("sw360:" + linkRelation), is(true));
// 
//         JsonNode sw360UsersNode = embeddedNode.get("sw360:" + linkRelation);
//         assertThat(sw360UsersNode.isArray(),is(true));
//         assertThat(sw360UsersNode.size(),is(embeddedArraySize));
// 
//         assertThat(responseBodyJsonNode.has("_links"), is(true));
// 
//         JsonNode linksNode = responseBodyJsonNode.get("_links");
//         assertThat(linksNode.has("curies"), is(true));
// 
//         JsonNode curiesNode = linksNode.get("curies").get(0);
//         assertThat(curiesNode.get("href").asText(), endsWith("docs/html5/{rel}.html"));
//         assertThat(curiesNode.get("name").asText(), is("sw360"));
//         assertThat(curiesNode.get("templated").asBoolean(), is(true));
//     }
// 
//     public static String getAccessToken(MockMvc mockMvc, String username, String password) throws Exception {
//         String authorizationHeaderValue = "Basic "
//                 + new String(Base64Utils.encode("trusted-sw360-client:sw360-secret".getBytes()));
// 
//         MockHttpServletResponse response = mockMvc
//                 .perform(post("/oauth/token")
//                         .header("Authorization", authorizationHeaderValue)
//                         .contentType(MediaType.APPLICATION_FORM_URLENCODED)
//                         .param("client_id", "trusted-sw360-client")
//                         .param("client_secret", "sw360-secret")
//                         .param("username", username)
//                         .param("password", password)
//                         .param("grant_type", "password")
//                         .param("scope", "sw360.read"))
//                 .andReturn().getResponse();
// 
//         return new ObjectMapper()
//                 .readValue(response.getContentAsByteArray(), OAuthToken.class)
//                 .accessToken;
//     }
// 
// 
//     @JsonIgnoreProperties(ignoreUnknown = true)
//     private static class OAuthToken {
//         @JsonProperty("access_token")
//         public String accessToken;
//     }
// 
// }
// 
// Path: subprojects/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/license/Sw360LicenseService.java
// @Service
// @RequiredArgsConstructor(onConstructor = @__(@Autowired))
// public class Sw360LicenseService {
//     @Value("${sw360.thrift-server-url:http://localhost:8080}")
//     private String thriftServerUrl;
// 
//     public List<License> getLicenses() {
//         try {
//             LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
//             return sw360LicenseClient.getLicenseSummary();
//         } catch (TException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public License getLicenseById(String licenseId) {
//         try {
//             LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
//             // TODO Kai Tödter 2017-01-26
//             // What is the semantics of the second parameter (organization)?
//             return sw360LicenseClient.getByID(licenseId, "?");
//         } catch (TException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public License createLicense(License license, User sw360User) {
//         try {
//             LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
//             license.setId(license.getShortname());
//             List<License> licenses = sw360LicenseClient.addLicenses(Collections.singletonList(license), sw360User);
//             for(License newlicense: licenses) {
//                 if(license.getFullname().equals(newlicense.getFullname())) {
//                     return  newlicense;
//                 }
//             }
//         } catch (TException e) {
//             throw new RuntimeException(e);
//         }
//         return null;
//     }
// 
//     private LicenseService.Iface getThriftLicenseClient() throws TTransportException {
//         THttpClient thriftClient = new THttpClient(thriftServerUrl + "/licenses/thrift");
//         TProtocol protocol = new TCompactProtocol(thriftClient);
//         return new LicenseService.Client(protocol);
//     }
// }


// Path: subprojects/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/LicenseSpec.java
import org.eclipse.sw360.datahandler.thrift.licenses.License;
import org.eclipse.sw360.rest.resourceserver.TestHelper;
import org.eclipse.sw360.rest.resourceserver.license.Sw360LicenseService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.MediaTypes;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.eq;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/*
 * Copyright Siemens AG, 2017. Part of the SW360 Portal Project.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.eclipse.sw360.rest.resourceserver.restdocs;




public class LicenseSpec extends RestDocsSpecBase {

    @MockBean
    private Sw360LicenseService licenseServiceMock;