Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commiting old local unit tests #20

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,57 @@
<description>The DB API of the OpenSmartCLIDE project.</description>

<properties>
<java.version>11</java.version>
<!-- it should be 11 -->
<java.version>8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<!-- MongoDB persistence -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<!-- unit testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<!-- Embedded MongoDB for unit testing -->
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>

<!-- Lombok dependency -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ public class ServiceController {
private MongoTemplate template;

@GetMapping("/services")
public List<Service> getAllServices(@RequestParam(value = "licence",required = false) String licence,
@RequestParam(value = "framework",required = false) String framework,
@RequestParam(value = "min_stars",required = false) String min_stars,
@RequestParam(value = "max_stars",required = false) String max_stars,
@RequestParam(value = "min_forks",required = false) String min_forks,
@RequestParam(value = "max_forks",required = false) String max_forks,
@RequestParam(value = "min_watchers",required = false) String min_watchers,
@RequestParam(value = "max_watchers",required = false) String max_watchers,
@RequestParam(value = "url",required = false) String url,
@RequestParam(value = "deployable",required = false) String deployable,
@RequestParam(value = "created_before",required = false) String created_before,
@RequestParam(value = "created_after",required = false) String created_after,
@RequestParam(value = "updated_before",required = false) String updated_before,
@RequestParam(value = "updated_after",required = false) String updated_after,
@RequestParam(value = "user_id",required = false) String userId,
@RequestParam(value = "registry_id",required = false) String registryId,
@RequestParam(value = "workspace_id",required = false) String workspaceId,
@RequestParam(value = "search",required = false) String search) throws ParseException {
public List<Service> getAllServices(@RequestParam(value = "licence", required = false) String licence,
@RequestParam(value = "framework", required = false) String framework,
@RequestParam(value = "min_stars", required = false) String min_stars,
@RequestParam(value = "max_stars", required = false) String max_stars,
@RequestParam(value = "min_forks", required = false) String min_forks,
@RequestParam(value = "max_forks", required = false) String max_forks,
@RequestParam(value = "min_watchers", required = false) String min_watchers,
@RequestParam(value = "max_watchers", required = false) String max_watchers,
@RequestParam(value = "url", required = false) String url,
@RequestParam(value = "deployable", required = false) String deployable,
@RequestParam(value = "created_before", required = false) String created_before,
@RequestParam(value = "created_after", required = false) String created_after,
@RequestParam(value = "updated_before", required = false) String updated_before,
@RequestParam(value = "updated_after", required = false) String updated_after,
@RequestParam(value = "user_id", required = false) String userId,
@RequestParam(value = "registry_id", required = false) String registryId,
@RequestParam(value = "workspace_id", required = false) String workspaceId,
@RequestParam(value = "search", required = false) String search) throws ParseException {
if (search != null) {
TextIndexDefinition textIndexDefinition = new TextIndexDefinition.TextIndexDefinitionBuilder()
.onField("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.TextIndexed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
import org.eclipse.opensmartclide.dbapi.model.Service;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.Date;
import java.util.List;

public interface ServiceRepository extends MongoRepository<Service, String> {
}
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#spring.data.mongodb.host=$MONGODB_HOST
#spring.data.mongodb.port=$MONGODB_PORT
spring.data.mongodb.database=smartclide
spring.mongodb.embedded.version=3.6.5
#spring.data.mongodb.username=$MONGODB_USERNAME
#spring.data.mongodb.password=$MONGODB_PASSWORD

#spring.data.mongodb.password=$MONGODB_PASSWORD
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.eclipse.opensmartclide.dbapi.repository;

import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.eclipse.opensmartclide.dbapi.model.CiManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@DataMongoTest
class CiManagerRepositoryTest {

@Autowired
private CiManagerRepository ciManagerRepository;

@BeforeEach
public void setUp() throws Exception {
CiManager ciManager = new CiManager();
ciManager.setId(Long.toString(1L));
ciManager.setUser_id("testCiManagerUserId");
ciManager.setType("testCiManagerType");
ciManager.setUrl("testCiManagerUrl");
ciManager.setUsername("testCiManagerUsername");
ciManager.setToken("testCiManagerToken");

ciManagerRepository.save(ciManager);
}

@Test
public void assertCiManagerIdPersisted() {
Optional<CiManager> ciManager = ciManagerRepository.findById(Long.toString(1L));
String ciManagerId = ciManager.get().getId();
assertEquals(Long.toString(1L), ciManagerId);
}

@Test
public void assertCiManagerUserIdPersisted() {
Optional<CiManager> ciManager = ciManagerRepository.findById(Long.toString(1L));
String ciManagerUserId = ciManager.get().getUser_id();
assertEquals("testCiManagerUserId", ciManagerUserId);
}

@Test
public void assertCiManagerTypePersisted() {
Optional<CiManager> ciManager = ciManagerRepository.findById(Long.toString(1L));
String ciManagerType = ciManager.get().getType();
assertEquals("testCiManagerType", ciManagerType);
}

@Test
public void assertCiManagerUrlPersisted() {
Optional<CiManager> ciManager = ciManagerRepository.findById(Long.toString(1L));
String ciManagerUrl = ciManager.get().getUrl();
assertEquals("testCiManagerUrl", ciManagerUrl);
}

@Test
public void assertCiManagerUsernamePersisted() {
Optional<CiManager> ciManager = ciManagerRepository.findById(Long.toString(1L));
String ciManagerUsername = ciManager.get().getUsername();
assertEquals("testCiManagerUsername", ciManagerUsername);
}

@Test
public void assertCiManagerTokenPersisted() {
Optional<CiManager> ciManager = ciManagerRepository.findById(Long.toString(1L));
String ciManagerToken = ciManager.get().getToken();
assertEquals("testCiManagerToken", ciManagerToken);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.eclipse.opensmartclide.dbapi.repository;

import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.eclipse.opensmartclide.dbapi.model.DeploymentPlatform;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@DataMongoTest
class DeploymentPlatformRepositoryTest {

@Autowired
private DeploymentPlatformRepository deploymentPlatformRepository;

@BeforeEach
public void setUp() throws Exception {
DeploymentPlatform deploymentPlatform = new DeploymentPlatform();
deploymentPlatform.setId(Long.toString(1L));
deploymentPlatform.setUser_id("testDeploymentPlatformUserId");
deploymentPlatform.setUrl("testDeploymentPlatformUrl");
deploymentPlatform.setUsername("testDeploymentPlatformUsername");
deploymentPlatform.setToken("testDeploymentPlatformToken");

deploymentPlatformRepository.save(deploymentPlatform);
}

@Test
public void assertDeploymentPlatformIdPersisted() {
Optional<DeploymentPlatform> deploymentPlatform = deploymentPlatformRepository.findById(Long.toString(1L));
String deploymentPlatformId = deploymentPlatform.get().getId();
assertEquals(Long.toString(1L), deploymentPlatformId);
}

@Test
public void assertDeploymentPlatformUserIdPersisted() {
Optional<DeploymentPlatform> deploymentPlatform = deploymentPlatformRepository.findById(Long.toString(1L));
String deploymentPlatformUserId = deploymentPlatform.get().getUser_id();
assertEquals("testDeploymentPlatformUserId", deploymentPlatformUserId);
}

@Test
public void assertDeploymentPlatformUrlPersisted() {
Optional<DeploymentPlatform> deploymentPlatform = deploymentPlatformRepository.findById(Long.toString(1L));
String deploymentPlatformUrl = deploymentPlatform.get().getUrl();
assertEquals("testDeploymentPlatformUrl", deploymentPlatformUrl);
}

@Test
public void assertDeploymentPlatformUsernamePersisted() {
Optional<DeploymentPlatform> deploymentPlatform = deploymentPlatformRepository.findById(Long.toString(1L));
String deploymentPlatformUsername = deploymentPlatform.get().getUsername();
assertEquals("testDeploymentPlatformUsername", deploymentPlatformUsername);
}

@Test
public void assertDeploymentPlatformTokenPersisted() {
Optional<DeploymentPlatform> deploymentPlatform = deploymentPlatformRepository.findById(Long.toString(1L));
String deploymentPlatformToken = deploymentPlatform.get().getToken();
assertEquals("testDeploymentPlatformToken", deploymentPlatformToken);
}

}
Loading