Skip to content

Commit

Permalink
feat: TsurugiConnector: Added of(applicationName, endpoint)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishidama committed Aug 23, 2024
1 parent 6509783 commit 7f12ee3
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public static TsurugiConnector of(String endpoint) {
return of(uri, NullCredential.INSTANCE, TgSessionOption.of());
}

/**
* create connector.
*
* @param applicationName application name
* @param endpoint the end-point URI
* @return connector
* @since X.X.X
*/
public static TsurugiConnector of(String applicationName, String endpoint) {
var uri = URI.create(endpoint);
return of(uri, NullCredential.INSTANCE, TgSessionOption.of()).setApplicationName(applicationName);
}

/**
* create connector.
*
Expand All @@ -53,6 +66,18 @@ public static TsurugiConnector of(URI endpoint) {
return of(endpoint, NullCredential.INSTANCE, TgSessionOption.of());
}

/**
* create connector.
*
* @param applicationName application name
* @param endpoint the end-point URI
* @return connector
* @since X.X.X
*/
public static TsurugiConnector of(String applicationName, URI endpoint) {
return of(endpoint, NullCredential.INSTANCE, TgSessionOption.of()).setApplicationName(applicationName);
}

/**
* create connector.
*
Expand All @@ -65,6 +90,20 @@ public static TsurugiConnector of(String endpoint, Credential credential) {
return of(uri, credential, TgSessionOption.of());
}

/**
* create connector.
*
* @param applicationName application name
* @param endpoint the end-point URI
* @param credential credential. if null, use NullCredential
* @return connector
* @since X.X.X
*/
public static TsurugiConnector of(String applicationName, String endpoint, Credential credential) {
var uri = URI.create(endpoint);
return of(uri, credential, TgSessionOption.of()).setApplicationName(applicationName);
}

/**
* create connector.
*
Expand All @@ -76,6 +115,19 @@ public static TsurugiConnector of(URI endpoint, Credential credential) {
return of(endpoint, credential, TgSessionOption.of());
}

/**
* create connector.
*
* @param applicationName application name
* @param endpoint the end-point URI
* @param credential credential. if null, use NullCredential
* @return connector
* @since X.X.X
*/
public static TsurugiConnector of(String applicationName, URI endpoint, Credential credential) {
return of(endpoint, credential, TgSessionOption.of()).setApplicationName(applicationName);
}

/**
* create connector.
*
Expand All @@ -89,6 +141,21 @@ public static TsurugiConnector of(@Nonnull String endpoint, @Nullable Credential
return of(uri, credential, sessionOption);
}

/**
* create connector.
*
* @param applicationName application name
* @param endpoint the end-point URI
* @param credential credential. if null, use NullCredential
* @param sessionOption session option. if null, use new SessionOption instance
* @return connector
* @since X.X.X
*/
public static TsurugiConnector of(String applicationName, @Nonnull String endpoint, @Nullable Credential credential, @Nullable TgSessionOption sessionOption) {
var uri = URI.create(endpoint);
return of(uri, credential, sessionOption).setApplicationName(applicationName);
}

/**
* create connector.
*
Expand All @@ -109,6 +176,20 @@ public static TsurugiConnector of(@Nonnull URI endpoint, @Nullable Credential cr
return connector;
}

/**
* create connector.
*
* @param applicationName application name
* @param endpoint the end-point URI
* @param credential credential. if null, use NullCredential
* @param sessionOption session option. if null, use new SessionOption instance
* @return connector
* @since X.X.X
*/
public static TsurugiConnector of(String applicationName, @Nonnull URI endpoint, @Nullable Credential credential, @Nullable TgSessionOption sessionOption) {
return of(endpoint, credential, sessionOption).setApplicationName(applicationName);
}

/** low connector */
protected final Connector lowConnector;
private final URI endpoint;
Expand Down Expand Up @@ -143,6 +224,10 @@ public URI getEndpoint() {
return this.endpoint;
}

Credential getCredential() {
return this.defaultCredential;
}

/**
* get session option.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -19,6 +20,7 @@
import com.tsurugidb.iceaxe.test.low.TestLowSession;
import com.tsurugidb.tsubakuro.channel.common.connection.Connector;
import com.tsurugidb.tsubakuro.channel.common.connection.Credential;
import com.tsurugidb.tsubakuro.channel.common.connection.NullCredential;
import com.tsurugidb.tsubakuro.channel.common.connection.UsernamePasswordCredential;
import com.tsurugidb.tsubakuro.common.Session;
import com.tsurugidb.tsubakuro.common.SessionBuilder;
Expand All @@ -27,6 +29,144 @@

class TsurugiConnectorTest {

@Test
void of_endpointStr() {
String endpoint = "tcp://test:12345";
var connector = TsurugiConnector.of(endpoint);
assertNull(connector.getApplicationName());
assertEquals(URI.create(endpoint), connector.getEndpoint());
assertSame(NullCredential.INSTANCE, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_name_endpointStr() {
String applicationName = "test-app";
String endpoint = "tcp://test:12345";
var connector = TsurugiConnector.of(applicationName, endpoint);
assertEquals(applicationName, connector.getApplicationName());
assertEquals(URI.create(endpoint), connector.getEndpoint());
assertSame(NullCredential.INSTANCE, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_endpointUri() {
URI endpoint = URI.create("tcp://test:12345");
var connector = TsurugiConnector.of(endpoint);
assertNull(connector.getApplicationName());
assertEquals(endpoint, connector.getEndpoint());
assertSame(NullCredential.INSTANCE, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_name_endpointUri() {
String applicationName = "test-app";
URI endpoint = URI.create("tcp://test:12345");
var connector = TsurugiConnector.of(applicationName, endpoint);
assertEquals(applicationName, connector.getApplicationName());
assertEquals(endpoint, connector.getEndpoint());
assertSame(NullCredential.INSTANCE, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_endpointStr_credential() {
String endpoint = "tcp://test:12345";
var credential = new UsernamePasswordCredential("test-user", "test-password");
var connector = TsurugiConnector.of(endpoint, credential);
assertNull(connector.getApplicationName());
assertEquals(URI.create(endpoint), connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_name_endpointStr_credential() {
String applicationName = "test-app";
String endpoint = "tcp://test:12345";
var credential = new UsernamePasswordCredential("test-user", "test-password");
var connector = TsurugiConnector.of(applicationName, endpoint, credential);
assertEquals(applicationName, connector.getApplicationName());
assertEquals(URI.create(endpoint), connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_endpointUri_credential() {
URI endpoint = URI.create("tcp://test:12345");
var credential = new UsernamePasswordCredential("test-user", "test-password");
var connector = TsurugiConnector.of(endpoint, credential);
assertNull(connector.getApplicationName());
assertEquals(endpoint, connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_name_endpointUri_credential() {
String applicationName = "test-app";
URI endpoint = URI.create("tcp://test:12345");
var credential = new UsernamePasswordCredential("test-user", "test-password");
var connector = TsurugiConnector.of(applicationName, endpoint, credential);
assertEquals(applicationName, connector.getApplicationName());
assertEquals(endpoint, connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertNotNull(connector.getSessionOption());
}

@Test
void of_endpointStr_credential_option() {
String endpoint = "tcp://test:12345";
var credential = new UsernamePasswordCredential("test-user", "test-password");
var sessionOption = TgSessionOption.of();
var connector = TsurugiConnector.of(endpoint, credential, sessionOption);
assertNull(connector.getApplicationName());
assertEquals(URI.create(endpoint), connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertSame(sessionOption, connector.getSessionOption());
}

@Test
void of_name_endpointStr_credential_option() {
String applicationName = "test-app";
String endpoint = "tcp://test:12345";
var credential = new UsernamePasswordCredential("test-user", "test-password");
var sessionOption = TgSessionOption.of();
var connector = TsurugiConnector.of(applicationName, endpoint, credential, sessionOption);
assertEquals(applicationName, connector.getApplicationName());
assertEquals(URI.create(endpoint), connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertSame(sessionOption, connector.getSessionOption());
}

@Test
void of_endpointUri_credential_option() {
URI endpoint = URI.create("tcp://test:12345");
var credential = new UsernamePasswordCredential("test-user", "test-password");
var sessionOption = TgSessionOption.of();
var connector = TsurugiConnector.of(endpoint, credential, sessionOption);
assertNull(connector.getApplicationName());
assertEquals(endpoint, connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertSame(sessionOption, connector.getSessionOption());
}

@Test
void of_name_endpointUri_credential_option() {
String applicationName = "test-app";
URI endpoint = URI.create("tcp://test:12345");
var credential = new UsernamePasswordCredential("test-user", "test-password");
var sessionOption = TgSessionOption.of();
var connector = TsurugiConnector.of(applicationName, endpoint, credential, sessionOption);
assertEquals(applicationName, connector.getApplicationName());
assertEquals(endpoint, connector.getEndpoint());
assertSame(credential, connector.getCredential());
assertSame(sessionOption, connector.getSessionOption());
}

@Test
void getEndpoint() {
var endpoint = URI.create("ipc:test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ static TsurugiConnector createConnector() {
var endpoint = URI.create("tcp://localhost:12345");
var credential = Example01Credential.getCredential();
var connector = TsurugiConnector.of(endpoint, credential);
// var connector = TsurugiConnector.of("application-name", endpoint, credential);
return connector;
}

static TsurugiConnector createConnectorString() {
static TsurugiConnector createConnector_endpointString() {
var endpoint = "tcp://localhost:12345";
var credential = Example01Credential.getCredential();
var connector = TsurugiConnector.of(endpoint, credential);
// var connector = TsurugiConnector.of("application-name", endpoint, credential);
return connector;
}

Expand All @@ -42,6 +44,7 @@ static TsurugiConnector createConnectorWithSessionOption() {
var credential = Example01Credential.getCredential();
var sessionOption = TgSessionOption.of().setTimeout(TgTimeoutKey.DEFAULT, 1, TimeUnit.MINUTES).setCommitType(TgCommitType.DEFAULT);
var connector = TsurugiConnector.of(endpoint, credential, sessionOption);
// var connector = TsurugiConnector.of("application-name", endpoint, credential, sessionOption);
return connector;
}
}

0 comments on commit 7f12ee3

Please sign in to comment.