Skip to content

Commit

Permalink
Fixed style errors.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Aug 25, 2022
1 parent 838659f commit 69369dc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class LegacySNSMessage extends LegacyBaseMessage {
private final String clusterName;

private LegacySNSMessage(
final String destinationName,
final String roleArn,
final String topicArn,
final String clusterName,
final String subject,
final String message
final String destinationName,
final String roleArn,
final String topicArn,
final String clusterName,
final String subject,
final String message
) {
super(LegacyDestinationType.LEGACY_SNS, destinationName, message);

Expand Down Expand Up @@ -66,13 +66,20 @@ public LegacySNSMessage(StreamInput streamInput) throws java.io.IOException {

@Override
public String toString() {
return "DestinationType: " + getChannelType()
+ ", DestinationName: " + destinationName
+ ", RoleARn: " + roleArn
+ ", TopicArn: " + topicArn
+ ", ClusterName: " + clusterName
+ ", Subject: " + subject
+ ", Message: " + message;
return "DestinationType: "
+ getChannelType()
+ ", DestinationName: "
+ destinationName
+ ", RoleARn: "
+ roleArn
+ ", TopicArn: "
+ topicArn
+ ", ClusterName: "
+ clusterName
+ ", Subject: "
+ subject
+ ", Message: "
+ message;
}

public static class Builder {
Expand Down Expand Up @@ -113,14 +120,7 @@ public Builder withClusterName(String clusterName) {
}

public LegacySNSMessage build() {
return new LegacySNSMessage(
this.destinationName,
this.roleArn,
this.topicArn,
this.clusterName,
this.subject,
this.message
);
return new LegacySNSMessage(this.destinationName, this.roleArn, this.topicArn, this.clusterName, this.subject, this.message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

package org.opensearch.commons.destination.util;

import java.util.regex.Pattern;

import org.opensearch.common.Strings;
import org.opensearch.common.ValidationException;

import java.util.regex.Pattern;

public class Util {
private Util() {}

public static final Pattern SNS_ARN_REGEX = Pattern.compile("^arn:aws(-[^:]+)?:sns:([a-zA-Z0-9-]+):([0-9]{12}):([a-zA-Z0-9-_]+)(\\.fifo)?$");
public static final Pattern SNS_ARN_REGEX = Pattern
.compile("^arn:aws(-[^:]+)?:sns:([a-zA-Z0-9-]+):([0-9]{12}):([a-zA-Z0-9-_]+)(\\.fifo)?$");
public static final Pattern IAM_ARN_REGEX = Pattern.compile("^arn:aws(-[^:]+)?:iam::([0-9]{12}):([a-zA-Z0-9-/_+=@.,]+)$");

public static String getRegion(String arn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

package org.opensearch.commons.destination.message;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class LegacySNSMessageTest {

@Test
Expand All @@ -24,8 +24,10 @@ public void testCreateRoleArnMissingMessage() {
@Test
public void testCreateTopicArnMissingMessage() {
try {
LegacySNSMessage message = new LegacySNSMessage.Builder("sms").withMessage("dummyMessage")
.withRole("arn:aws:iam::853806060000:role/domain/abc").build();
LegacySNSMessage message = new LegacySNSMessage.Builder("sms")
.withMessage("dummyMessage")
.withRole("arn:aws:iam::853806060000:role/domain/abc")
.build();
} catch (Exception ex) {
assertEquals("Topic arn is missing/invalid: null", ex.getMessage());
throw ex;
Expand All @@ -36,8 +38,9 @@ public void testCreateTopicArnMissingMessage() {
public void testCreateContentMissingMessage() {
try {
LegacySNSMessage message = new LegacySNSMessage.Builder("sms")
.withRole("arn:aws:iam::853806060000:role/domain/abc")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification").build();
.withRole("arn:aws:iam::853806060000:role/domain/abc")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification")
.build();
} catch (Exception ex) {
assertEquals("Message content is missing", ex.getMessage());
throw ex;
Expand All @@ -47,9 +50,11 @@ public void testCreateContentMissingMessage() {
@Test
public void testInValidRoleMessage() {
try {
LegacySNSMessage message = new LegacySNSMessage.Builder("sms").withMessage("dummyMessage")
.withRole("dummyRole")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification").build();
LegacySNSMessage message = new LegacySNSMessage.Builder("sms")
.withMessage("dummyMessage")
.withRole("dummyRole")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification")
.build();
} catch (Exception ex) {
assertEquals("Role arn is missing/invalid: dummyRole", ex.getMessage());
throw ex;
Expand All @@ -58,9 +63,11 @@ public void testInValidRoleMessage() {

@Test
public void testValidMessage() {
LegacySNSMessage message = new LegacySNSMessage.Builder("sms").withMessage("dummyMessage")
.withRole("arn:aws:iam::853806060000:role/domain/abc")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification").build();
LegacySNSMessage message = new LegacySNSMessage.Builder("sms")
.withMessage("dummyMessage")
.withRole("arn:aws:iam::853806060000:role/domain/abc")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification")
.build();
assertEquals(LegacyDestinationType.LEGACY_SNS, message.getChannelType());
assertEquals("sms", message.getChannelName());
assertEquals("dummyMessage", message.getMessage());
Expand All @@ -71,9 +78,11 @@ public void testValidMessage() {
@Test
public void testInValidChannelName() {
try {
LegacySNSMessage message = new LegacySNSMessage.Builder("").withMessage("dummyMessage")
.withRole("arn:aws:iam::853806060000:role/domain/abc")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification").build();
LegacySNSMessage message = new LegacySNSMessage.Builder("")
.withMessage("dummyMessage")
.withRole("arn:aws:iam::853806060000:role/domain/abc")
.withTopicArn("arn:aws:sns:us-west-2:475313751589:test-notification")
.build();
} catch (Exception ex) {
assertEquals("Channel name must be defined", ex.getMessage());
throw ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

package org.opensearch.commons.destination.util;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class UtilTest {

@Test
Expand Down

0 comments on commit 69369dc

Please sign in to comment.