Skip to content

Commit 0095dff

Browse files
committed
Use more lombok annotations to reduce boilerplate code
1 parent 2c4fc47 commit 0095dff

File tree

1 file changed

+32
-83
lines changed

1 file changed

+32
-83
lines changed

src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java

Lines changed: 32 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import com.couchbase.client.java.env.CouchbaseEnvironment;
2323
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
2424
import com.couchbase.client.java.query.Index;
25+
import lombok.AllArgsConstructor;
2526
import lombok.Getter;
27+
import lombok.experimental.Wither;
2628
import org.testcontainers.containers.GenericContainer;
2729
import org.testcontainers.containers.wait.HttpWaitStrategy;
2830

@@ -40,39 +42,54 @@
4042
* <p>
4143
* Optimized by ctayeb
4244
*/
45+
@AllArgsConstructor
4346
public class CouchbaseContainer<SELF extends CouchbaseContainer<SELF>> extends GenericContainer<SELF> {
4447

48+
@Wither
4549
private String memoryQuota = "300";
4650

51+
@Wither
4752
private String indexMemoryQuota = "300";
4853

54+
@Wither
4955
private String clusterUsername = "Administrator";
5056

57+
@Wither
5158
private String clusterPassword = "password";
5259

60+
@Wither
5361
private boolean keyValue = true;
5462

5563
@Getter
64+
@Wither
5665
private boolean query = true;
5766

5867
@Getter
68+
@Wither
5969
private boolean index = true;
6070

6171
@Getter
72+
@Wither
6273
private boolean primaryIndex = true;
6374

6475
@Getter
76+
@Wither
6577
private boolean fts = false;
6678

79+
@Wither
6780
private boolean beerSample = false;
6881

82+
@Wither
6983
private boolean travelSample = false;
7084

85+
@Wither
7186
private boolean gamesIMSample = false;
7287

73-
private CouchbaseEnvironment couchbaseEnvironment;
88+
@Getter(lazy = true)
89+
private final CouchbaseEnvironment couchbaseEnvironment = createCouchbaseEnvironment();
7490

75-
private CouchbaseCluster couchbaseCluster;
91+
@Getter(lazy = true)
92+
private final CouchbaseCluster couchbaseCluster = createCouchbaseCluster();
7693

7794
private List<BucketSettings> newBuckets = new ArrayList<>();
7895

@@ -106,92 +123,11 @@ protected void configure() {
106123
setWaitStrategy(new HttpWaitStrategy().forPath("/ui/index.html#/"));
107124
}
108125

109-
public CouchbaseEnvironment getCouchbaseEnvironment() {
110-
if (couchbaseEnvironment == null) {
111-
initCluster();
112-
couchbaseEnvironment = DefaultCouchbaseEnvironment.builder()
113-
.bootstrapCarrierDirectPort(getMappedPort(11210))
114-
.bootstrapCarrierSslPort(getMappedPort(11207))
115-
.bootstrapHttpDirectPort(getMappedPort(8091))
116-
.bootstrapHttpSslPort(getMappedPort(18091))
117-
.build();
118-
}
119-
return couchbaseEnvironment;
120-
}
121-
122-
public CouchbaseCluster getCouchbaseCluster() {
123-
if (couchbaseCluster == null) {
124-
couchbaseCluster = CouchbaseCluster.create(getCouchbaseEnvironment(), getContainerIpAddress());
125-
}
126-
return couchbaseCluster;
127-
}
128-
129-
public SELF withClusterUsername(String username) {
130-
this.clusterUsername = username;
131-
return self();
132-
}
133-
134-
public SELF withClusterPassword(String password) {
135-
this.clusterPassword = password;
136-
return self();
137-
}
138-
139-
public SELF withMemoryQuota(String memoryQuota) {
140-
this.memoryQuota = memoryQuota;
141-
return self();
142-
}
143-
144-
public SELF withIndexMemoryQuota(String indexMemoryQuota) {
145-
this.indexMemoryQuota = indexMemoryQuota;
146-
return self();
147-
}
148-
149-
public SELF withKeyValue(boolean withKV) {
150-
this.keyValue = withKV;
151-
return self();
152-
}
153-
154-
public SELF withIndex(boolean withIndex) {
155-
this.index = withIndex;
156-
return self();
157-
}
158-
159-
public SELF withPrimaryIndex(boolean primaryIndex) {
160-
this.primaryIndex = primaryIndex;
161-
return self();
162-
}
163-
164-
public SELF withQuery(boolean withQuery) {
165-
this.query = withQuery;
166-
return self();
167-
}
168-
169-
public SELF withFTS(boolean withFTS) {
170-
this.fts = withFTS;
171-
return self();
172-
}
173-
174-
public SELF withTravelSample() {
175-
this.travelSample = true;
176-
return self();
177-
}
178-
179-
public SELF withBeerSample() {
180-
this.beerSample = true;
181-
return self();
182-
}
183-
184-
public SELF withGamesIMSample() {
185-
this.gamesIMSample = true;
186-
return self();
187-
}
188-
189126
public SELF withNewBucket(BucketSettings bucketSettings) {
190127
newBuckets.add(bucketSettings);
191128
return self();
192129
}
193130

194-
195131
public void initCluster() {
196132
urlBase = String.format("http://%s:%s", getContainerIpAddress(), getMappedPort(8091));
197133
try {
@@ -295,4 +231,17 @@ public void start() {
295231
}
296232
}
297233

234+
private CouchbaseCluster createCouchbaseCluster() {
235+
return CouchbaseCluster.create(getCouchbaseEnvironment(), getContainerIpAddress());
236+
}
237+
238+
private DefaultCouchbaseEnvironment createCouchbaseEnvironment() {
239+
initCluster();
240+
return DefaultCouchbaseEnvironment.builder()
241+
.bootstrapCarrierDirectPort(getMappedPort(11210))
242+
.bootstrapCarrierSslPort(getMappedPort(11207))
243+
.bootstrapHttpDirectPort(getMappedPort(8091))
244+
.bootstrapHttpSslPort(getMappedPort(18091))
245+
.build();
246+
}
298247
}

0 commit comments

Comments
 (0)