Remove OrionConfiguration (#644)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Puneetha Karamsetty 6 years ago committed by CJ Hare
parent 8fcee3222a
commit d6a04f416b
  1. 1
      ethereum/core/build.gradle
  2. 18
      orion/src/integration-test/java/tech/pegasys/pantheon/orion/OrionTest.java
  3. 12
      orion/src/main/java/tech/pegasys/pantheon/orion/Orion.java
  4. 49
      orion/src/main/java/tech/pegasys/pantheon/orion/OrionConfiguration.java
  5. 4
      orion/src/main/java/tech/pegasys/pantheon/orion/types/ReceiveRequest.java
  6. 4
      orion/src/main/java/tech/pegasys/pantheon/orion/types/SendRequest.java

@ -32,6 +32,7 @@ dependencies {
implementation project(':ethereum:trie') implementation project(':ethereum:trie')
implementation project(':ethereum:permissioning') implementation project(':ethereum:permissioning')
implementation project(':metrics') implementation project(':metrics')
implementation project(':orion')
implementation project(':services:kvstore') implementation project(':services:kvstore')
implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-databind'

@ -17,9 +17,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import tech.pegasys.orion.testutil.OrionTestHarness; import tech.pegasys.orion.testutil.OrionTestHarness;
import tech.pegasys.pantheon.orion.types.ReceiveContent; import tech.pegasys.pantheon.orion.types.ReceiveRequest;
import tech.pegasys.pantheon.orion.types.ReceiveResponse; import tech.pegasys.pantheon.orion.types.ReceiveResponse;
import tech.pegasys.pantheon.orion.types.SendContent; import tech.pegasys.pantheon.orion.types.SendRequest;
import tech.pegasys.pantheon.orion.types.SendResponse; import tech.pegasys.pantheon.orion.types.SendResponse;
import java.io.IOException; import java.io.IOException;
@ -46,10 +46,7 @@ public class OrionTest {
testHarness = OrionTestHarness.create(folder.newFolder().toPath()); testHarness = OrionTestHarness.create(folder.newFolder().toPath());
OrionConfiguration orionConfiguration = OrionConfiguration.createDefault(); orion = new Orion(testHarness.getConfig().clientUrl().toString());
orionConfiguration.setUrl(testHarness.getConfig().clientUrl().toString());
orion = new Orion(orionConfiguration);
} }
@AfterClass @AfterClass
@ -66,10 +63,10 @@ public class OrionTest {
public void testSendAndReceive() throws IOException { public void testSendAndReceive() throws IOException {
List<String> publicKeys = testHarness.getPublicKeys(); List<String> publicKeys = testHarness.getPublicKeys();
SendContent sc = new SendContent(PAYLOAD, publicKeys.get(0), new String[] {publicKeys.get(1)}); SendRequest sc = new SendRequest(PAYLOAD, publicKeys.get(0), new String[] {publicKeys.get(1)});
SendResponse sr = orion.send(sc); SendResponse sr = orion.send(sc);
ReceiveContent rc = new ReceiveContent(sr.getKey(), publicKeys.get(1)); ReceiveRequest rc = new ReceiveRequest(sr.getKey(), publicKeys.get(1));
ReceiveResponse rr = orion.receive(rc); ReceiveResponse rr = orion.receive(rc);
assertEquals(PAYLOAD, new String(rr.getPayload(), UTF_8)); assertEquals(PAYLOAD, new String(rr.getPayload(), UTF_8));
@ -77,10 +74,7 @@ public class OrionTest {
@Test(expected = IOException.class) @Test(expected = IOException.class)
public void whenUpCheckFailsThrows() throws IOException { public void whenUpCheckFailsThrows() throws IOException {
OrionConfiguration configuration = OrionConfiguration.createDefault(); Orion broken = new Orion("http:");
configuration.setUrl("http:");
Orion broken = new Orion(configuration);
broken.upCheck(); broken.upCheck();
} }

@ -12,9 +12,9 @@
*/ */
package tech.pegasys.pantheon.orion; package tech.pegasys.pantheon.orion;
import tech.pegasys.pantheon.orion.types.ReceiveContent; import tech.pegasys.pantheon.orion.types.ReceiveRequest;
import tech.pegasys.pantheon.orion.types.ReceiveResponse; import tech.pegasys.pantheon.orion.types.ReceiveResponse;
import tech.pegasys.pantheon.orion.types.SendContent; import tech.pegasys.pantheon.orion.types.SendRequest;
import tech.pegasys.pantheon.orion.types.SendResponse; import tech.pegasys.pantheon.orion.types.SendResponse;
import java.io.IOException; import java.io.IOException;
@ -36,8 +36,8 @@ public class Orion {
private String url; private String url;
private OkHttpClient client; private OkHttpClient client;
public Orion(final OrionConfiguration orionConfiguration) { public Orion(final String orionUrl) {
this.url = orionConfiguration.getUrl(); this.url = orionUrl;
this.client = new OkHttpClient(); this.client = new OkHttpClient();
} }
@ -52,11 +52,11 @@ public class Orion {
} }
} }
public SendResponse send(final SendContent content) throws IOException { public SendResponse send(final SendRequest content) throws IOException {
return executePost("/send", objectMapper.writeValueAsString(content), SendResponse.class); return executePost("/send", objectMapper.writeValueAsString(content), SendResponse.class);
} }
public ReceiveResponse receive(final ReceiveContent content) throws IOException { public ReceiveResponse receive(final ReceiveRequest content) throws IOException {
return executePost("/receive", objectMapper.writeValueAsString(content), ReceiveResponse.class); return executePost("/receive", objectMapper.writeValueAsString(content), ReceiveResponse.class);
} }

@ -1,49 +0,0 @@
/*
* Copyright 2019 ConsenSys AG.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 tech.pegasys.pantheon.orion;
public class OrionConfiguration {
private static final String DEFAULT_ORION_URL = "http://localhost:8888";
private boolean enabled;
private String url;
public static OrionConfiguration createDefault() {
final OrionConfiguration config = new OrionConfiguration();
config.setEnabled(false);
config.setUrl(DEFAULT_ORION_URL);
return config;
}
@Override
public String toString() {
return "OrionConfiguration{" + "enabled=" + enabled + ", url='" + url + '\'' + '}';
}
public void setUrl(final String url) {
this.url = url;
}
public String getUrl() {
return this.url;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
}

@ -12,11 +12,11 @@
*/ */
package tech.pegasys.pantheon.orion.types; package tech.pegasys.pantheon.orion.types;
public class ReceiveContent { public class ReceiveRequest {
private String key; private String key;
private String to; private String to;
public ReceiveContent(final String key, final String to) { public ReceiveRequest(final String key, final String to) {
this.key = key; this.key = key;
this.to = to; this.to = to;

@ -14,12 +14,12 @@ package tech.pegasys.pantheon.orion.types;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
public class SendContent { public class SendRequest {
private byte[] payload; private byte[] payload;
private String from; private String from;
private String[] to; private String[] to;
public SendContent(final String payload, final String from, final String[] to) { public SendRequest(final String payload, final String from, final String[] to) {
this.payload = payload.getBytes(UTF_8); this.payload = payload.getBytes(UTF_8);
this.from = from; this.from = from;
this.to = to; this.to = to;
Loading…
Cancel
Save