Ensure configuration can be serialized

Closes gh-506
This commit is contained in:
Stephane Nicoll
2017-09-18 15:02:01 +02:00
parent d50d7667e3
commit 8efe5f34be
5 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.initializr.service;
import java.net.URI;
import java.net.URISyntaxException;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Basic smoke tests for {@link InitializrService}.
*
* @author Stephane Nicoll
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class InitializrServiceSmokeTests {
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private InitializrMetadataProvider metadataProvider;
@Test
public void metadataCanBeSerialized() throws URISyntaxException {
RequestEntity<Void> request = RequestEntity.get(new URI("/"))
.accept(MediaType.parseMediaType("application/vnd.initializr.v2.1+json"))
.build();
ResponseEntity<String> response = this.restTemplate.exchange(request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
new JSONObject(response.getBody());
}
@Test
public void configurationCanBeSerialized() throws URISyntaxException {
RequestEntity<Void> request = RequestEntity.get(new URI("/metadata/config"))
.accept(MediaType.APPLICATION_JSON)
.build();
ResponseEntity<String> response = this.restTemplate.exchange(request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
InitializrMetadata actual = InitializrMetadataBuilder.create()
.withInitializrMetadata(new ByteArrayResource(
response.getBody().getBytes()))
.build();
assertThat(actual).isNotNull();
InitializrMetadata expected = metadataProvider.get();
assertThat(actual.getDependencies().getAll().size())
.isEqualTo(expected.getDependencies().getAll().size());
assertThat(actual.getConfiguration().getEnv().getBoms().size())
.isEqualTo(expected.getConfiguration().getEnv().getBoms().size());
}
}