Skip to content

Commit

Permalink
Merge pull request #407 from terrestris/add-controller-integration-tests
Browse files Browse the repository at this point in the history
Add controller integration tests
  • Loading branch information
dnlkoch authored Oct 19, 2021
2 parents a0509d8 + fffcf20 commit 985d81e
Show file tree
Hide file tree
Showing 19 changed files with 1,094 additions and 39 deletions.
26 changes: 12 additions & 14 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
header:
license:
spdx-id: Apache-2.0
copyright-owner: terrestris GmbH & Co. KG
content: |
SHOGun, https://terrestris.github.io/shogun/
pattern: |
SHOGun, https://terrestris.github.io/shogun/
Copyright © 2020-present terrestris GmbH & Co. KG
Copyright © \d{4}-present terrestris GmbH & Co. KG
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
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
https://www.apache.org/licenses/LICENSE-2.0.txt
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.
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.
paths-ignore:
- '.github'
Expand All @@ -39,5 +36,6 @@ header:
- 'docs'
- '**/*.md'
- '**/*.sql'
- '**/*.iml'

comment: on-failure
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,12 @@
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring-security.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
5 changes: 4 additions & 1 deletion shogun-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -83,6 +82,10 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
</dependency>

<!-- Database driver -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ public class ResourceController {
@Value("${KEYCLOAK_HOST:1.2.3.4}")
String keycloakHost;

@Autowired
@Autowired(required = false)
BuildProperties buildProperties;

@RequestMapping("/")
public ModelAndView home(ModelAndView modelAndView) {
modelAndView.addObject("version", buildProperties.getVersion());
String buildVersion = "@VERSION@";
if (buildProperties != null) {
buildVersion = buildProperties.getVersion();
}
modelAndView.addObject("version", buildVersion);
modelAndView.setViewName("index");

return modelAndView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.zaxxer.hikari.HikariDataSource;
import org.junit.AfterClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
Expand Down Expand Up @@ -57,7 +59,7 @@ public PostgreSQLContainer postgreSQLContainer() {
if (postgreSQLContainer != null) {
return postgreSQLContainer;
}
DockerImageName postgis = DockerImageName.parse("docker.terrestris.de/postgis/postgis:11-3.0").asCompatibleSubstituteFor("postgres");
DockerImageName postgis = DockerImageName.parse("postgis/postgis:13-3.1-alpine").asCompatibleSubstituteFor("postgres");
postgreSQLContainer = new PostgreSQLContainer(postgis);
postgreSQLContainer.start();
return postgreSQLContainer;
Expand All @@ -66,7 +68,7 @@ public PostgreSQLContainer postgreSQLContainer() {
@Bean
public DataSource dataSource(final JdbcDatabaseContainer databaseContainer) {
HikariConfig hikariConfig = new HikariConfig();
String jdbcUrl = String.format("%s&currentSchema=shogun", databaseContainer.getJdbcUrl());
String jdbcUrl = String.format("%s?currentSchema=shogun", databaseContainer.getJdbcUrl());
hikariConfig.setJdbcUrl(jdbcUrl);
hikariConfig.setUsername(databaseContainer.getUsername());
hikariConfig.setPassword(databaseContainer.getPassword());
Expand All @@ -93,6 +95,8 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
jpaProperties.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
jpaProperties.put("hibernate.default_schema", env.getProperty("hibernate.default_schema"));
jpaProperties.put("hibernate.integration.envers.enabled", false);
jpaProperties.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName());
jpaProperties.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class.getName());

result.setJpaPropertyMap(jpaProperties);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* SHOGun, https://terrestris.github.io/shogun/
*
* Copyright © 2021-present terrestris GmbH & Co. KG
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* 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 de.terrestris.shogun.boot.controller;

import de.terrestris.shogun.lib.controller.ApplicationController;
import de.terrestris.shogun.lib.model.Application;
import de.terrestris.shogun.lib.model.Group;
import de.terrestris.shogun.lib.repository.ApplicationRepository;

import java.util.ArrayList;
import java.util.List;

public class ApplicationControllerTest extends BaseControllerTest<ApplicationController, ApplicationRepository, Application> {

public void setBaseEntity() {
entityClass = Application.class;
}

public void setBasePath() {
basePath = "/applications";
}

public void insertTestData() {
Application entity1 = new Application();
Application entity2 = new Application();
Application entity3 = new Application();

entity1.setName("Application 1");
entity2.setName("Application 2");
entity3.setName("Application 3");

ArrayList<Application> entities = new ArrayList<>();

entities.add(entity1);
entities.add(entity2);
entities.add(entity3);

List<Application> persistedEntities = (List<Application>) repository.saveAll(entities);

testData = persistedEntities;
}

}
Loading

0 comments on commit 985d81e

Please sign in to comment.