Skip to content

Commit d54ce89

Browse files
Denis RosaDenis Rosa
authored andcommitted
Fixing tests and code
1 parent a305753 commit d54ce89

File tree

19 files changed

+368
-588
lines changed

19 files changed

+368
-588
lines changed

.gitpod.Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM deniswsrosa/couchbase6.6.2-gitpod
2+
3+
#Simple example on how to extend the image to install Java and maven
4+
RUN apt-get -qq update && \
5+
apt-get install -yq maven default-jdk

.gitpod.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
image:
2+
file: .gitpod.Dockerfile
3+
4+
tasks:
5+
- name: Start Couchbase
6+
command: cd /opt/couchbase/ && ./start-cb.sh
7+
- name: Start app
8+
init: ./mvnw package -DskipTests
9+
command: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' -u Administrator:password localhost:8091/pools/default/buckets/user_profile)" != "200" ]]; do sleep 5; done && java -jar target/*.jar
10+
11+
# exposed ports
12+
ports:
13+
- port: 8080
14+
onOpen: open-preview
15+
- port: 8091
16+
onOpen: notify
17+
- port: 8092-10000
18+
onOpen: ignore
19+
- port: 4369
20+
onOpen: ignore
21+
22+
github:
23+
prebuilds:
24+
# enable for the master/default branch (defaults to true)
25+
master: true
26+
27+
vscode:
28+
extensions:
29+
- redhat.java
30+
- vscjava.vscode-java-debug
31+
- vscjava.vscode-java-test
32+
- pivotal.vscode-spring-boot

src.iml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="Spring" name="Spring">
5+
<configuration />
6+
</facet>
7+
<facet type="web" name="Web">
8+
<configuration>
9+
<webroots />
10+
<sourceRoots>
11+
<root url="file://$MODULE_DIR$/src/main/java" />
12+
<root url="file://$MODULE_DIR$/src/main/resources" />
13+
</sourceRoots>
14+
</configuration>
15+
</facet>
16+
</component>
317
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
418
<output url="file://$MODULE_DIR$/target/classes" />
519
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package org.couchbase.quickstart;
22

3-
import org.couchbase.quickstart.helpers.DatabaseHelper;
3+
import org.couchbase.quickstart.runners.DBSetupRunner;
4+
import org.springframework.beans.factory.annotation.Autowired;
45
import org.springframework.boot.SpringApplication;
56
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
67
import org.springframework.boot.autoconfigure.SpringBootApplication;
78

8-
//disables login since apis are open to public
99
@SpringBootApplication(exclude = SecurityAutoConfiguration.class, proxyBeanMethods = false)
1010
public class Application {
1111

12+
@Autowired
13+
private DBSetupRunner helper;
14+
1215
public static void main(String[] args) {
1316
SpringApplication.run(Application.class, args);
14-
15-
//bootstrap database
16-
DatabaseHelper dbHelper = new DatabaseHelper();
17-
dbHelper.createDb();
1817
}
1918

2019
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.couchbase.quickstart.configs;
2+
3+
public class CollectionNames {
4+
5+
public static final String PROFILE = "profile";
6+
}

src/main/java/org/couchbase/quickstart/configs/ConfigDb.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,36 @@
11
package org.couchbase.quickstart.configs;
22

3-
import org.springframework.beans.factory.annotation.Value;
3+
import com.couchbase.client.core.error.BucketExistsException;
4+
import com.couchbase.client.java.Bucket;
5+
import com.couchbase.client.java.Cluster;
6+
import com.couchbase.client.java.manager.bucket.BucketSettings;
7+
import com.couchbase.client.java.manager.bucket.BucketType;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.context.annotation.Bean;
410
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.stereotype.Component;
512

613
@Configuration
714
public class CouchbaseConfig {
815

9-
@Value("${spring.couchbase.bootstrap-hosts}")
10-
private String connectionString;
16+
@Autowired
17+
private DBProperties dbProp;
1118

12-
@Value("${spring.couchbase.bucket.name}")
13-
private String bucket;
14-
15-
@Value("${spring.couchbase.bucket.user}")
16-
private String username;
17-
18-
@Value("${spring.couchbase.bucket.password}")
19-
private String password;
20-
21-
@Value("${spring.couchbase.bucket.collection}")
22-
private String collection;
23-
24-
@Value("${spring.couchbase.bucket.scope}")
25-
private String scope;
26-
27-
public String getConnectionString() {
28-
return connectionString;
19+
@Bean
20+
public Cluster getCouchbaseCluster(){
21+
return Cluster.connect(dbProp.getHostName(), dbProp.getUsername(), dbProp.getPassword());
2922
}
3023

31-
public String getUserName() {
32-
return username;
33-
}
34-
35-
public String getPassword() { return password; }
24+
@Bean
25+
public Bucket getCouchbaseBucket(Cluster cluster){
3626

37-
public String getBucketName() {
38-
return bucket;
27+
//Creates the cluster if it does not exist yet
28+
if( !cluster.buckets().getAllBuckets().containsKey(dbProp.getBucketName())) {
29+
cluster.buckets().createBucket(BucketSettings.create(dbProp.getBucketName())
30+
.bucketType(BucketType.COUCHBASE)
31+
.ramQuotaMB(256));
32+
}
33+
return cluster.bucket(dbProp.getBucketName());
3934
}
4035

41-
public String getCollection(){
42-
return collection;
43-
}
44-
45-
public String getScope() {
46-
return scope;
47-
}
4836
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.couchbase.quickstart.configs;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
public class DBProperties {
8+
9+
@Value("${spring.couchbase.bootstrap-hosts}")
10+
private String hostName;
11+
@Value("${spring.couchbase.bucket.user}")
12+
private String username;
13+
@Value("${spring.couchbase.bucket.password}")
14+
private String password;
15+
@Value("${spring.couchbase.bucket.name}")
16+
private String bucketName;
17+
18+
public String getHostName() {
19+
return hostName;
20+
}
21+
public String getUsername() {
22+
return username;
23+
}
24+
public String getPassword() {
25+
return password;
26+
}
27+
public String getBucketName() {
28+
return bucketName;
29+
}
30+
31+
32+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.couchbase.quickstart.configs;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6+
7+
@Configuration
8+
public class WebConfiguration implements WebMvcConfigurer {
9+
10+
@Override
11+
public void addViewControllers(ViewControllerRegistry registry) {
12+
registry.addRedirectViewController("/", "swagger-ui/");
13+
}
14+
}

0 commit comments

Comments
 (0)