http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/validation/constraints/E164Validator.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/validation/constraints/E164Validator.java b/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/validation/constraints/E164Validator.java new file mode 100644 index 0000000..d8160f7 --- /dev/null +++ b/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/validation/constraints/E164Validator.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.validation.constraints; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import com.google.i18n.phonenumbers.NumberParseException; +import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; +import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; + +/** + * Checks that a given character sequence (e.g. string) is a valid E164 formatted phonenumber. https://www.cmtelecom.com/newsroom/how-to-format-international-telephone- numbers + * https://github.com/googlei18n/libphonenumber + */ +public class E164Validator implements ConstraintValidator<E164, String> { + + private final PhoneNumberUtil pnu = PhoneNumberUtil.getInstance(); + + @Override + public void initialize(final E164 constraintAnnotation) { + } + + @Override + public boolean isValid(final String value, final ConstraintValidatorContext context) { + + if (value == null) { + return false; + } + try { + + final PhoneNumber parsingResult = pnu.parse(value, null); + if (!pnu.format(parsingResult, PhoneNumberFormat.E164).equals(value)) { + return false; + } + return true; + } catch (final NumberParseException t) { + // Errors when parsing phonenumber + return false; + } + + // CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN + // log.debug("Phone Number: {}", value); + // log.debug("Country code: {}", numberProto.getCountryCode()); + // log.debug("National Number: {}", numberProto.getNationalNumber()); + // log.debug("E164 format: {}", pnu.format(numberProto, + // PhoneNumberFormat.E164)); + + } + +}
http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/main/resources/META-INF/services/org/apache/camel/component/cm-sms ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/main/resources/META-INF/services/org/apache/camel/component/cm-sms b/components/camel-cm-sms/src/main/resources/META-INF/services/org/apache/camel/component/cm-sms new file mode 100644 index 0000000..bf9d84b --- /dev/null +++ b/components/camel-cm-sms/src/main/resources/META-INF/services/org/apache/camel/component/cm-sms @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +class=org.apache.camel.component.cm.CMComponent http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/main/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/main/resources/log4j.properties b/components/camel-cm-sms/src/main/resources/log4j.properties new file mode 100644 index 0000000..0ada021 --- /dev/null +++ b/components/camel-cm-sms/src/main/resources/log4j.properties @@ -0,0 +1,41 @@ +## ------------------------------------------------------------------------ +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You 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. +## ------------------------------------------------------------------------ + +# +# The logging properties used for testing +# +log4j.rootLogger=INFO, file + +# uncomment the following to enable camel debugging +#log4j.logger.org.apache.camel.component.cm=TRACE +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +#log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +# MDC +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.file.file=target/camel-cm-sms-test.log +# MDC +#log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMConfigurationTest.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMConfigurationTest.java new file mode 100644 index 0000000..b4135ec --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMConfigurationTest.java @@ -0,0 +1,142 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test; + +import java.util.Set; +import java.util.UUID; + +import javax.validation.ConstraintViolation; +import javax.validation.Validator; + +import org.apache.camel.component.cm.CMConfiguration; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.Assert; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { ValidatorConfiguration.class }) +// @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +// @DisableJmx(false) +// @FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class CMConfigurationTest extends AbstractJUnit4SpringContextTests { + + @Autowired + private Validator validator; + + @Before + public void beforeTest() throws Exception { + } + + // @After + // public void afterTest() { + + @Test + public void testNullProductToken() throws Exception { + + final CMConfiguration configuration = new CMConfiguration(); + + // length: 1-11 + configuration.setDefaultFrom("DefaultFrom"); + configuration.setProductToken(null); + configuration.setDefaultMaxNumberOfParts(8); + configuration.setTestConnectionOnStartup(false); + + final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator.validate(configuration); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testNullDefaultFrom() throws Exception { + + final CMConfiguration configuration = new CMConfiguration(); + + // length: 1-11 + configuration.setDefaultFrom(null); + + configuration.setProductToken(UUID.randomUUID().toString()); + configuration.setDefaultMaxNumberOfParts(8); + configuration.setTestConnectionOnStartup(false); + + final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator.validate(configuration); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testDefaultFromFieldMaxLength() throws Exception { + + final CMConfiguration configuration = new CMConfiguration(); + + // length: 1-11 + configuration.setDefaultFrom("123456789012"); + + configuration.setProductToken(UUID.randomUUID().toString()); + configuration.setDefaultMaxNumberOfParts(8); + configuration.setTestConnectionOnStartup(false); + + final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator.validate(configuration); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testDefaultFromFieldZeroLength() throws Exception { + + final CMConfiguration configuration = new CMConfiguration(); + + // length: 1-11 + configuration.setDefaultFrom(""); + + configuration.setProductToken(UUID.randomUUID().toString()); + configuration.setDefaultMaxNumberOfParts(8); + configuration.setTestConnectionOnStartup(false); + + final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator.validate(configuration); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testMaxNumberOfParts() throws Exception { + + final CMConfiguration configuration = new CMConfiguration(); + + configuration.setProductToken(UUID.randomUUID().toString()); + configuration.setDefaultFrom("DefaultFrom"); + configuration.setDefaultMaxNumberOfParts(9); + configuration.setTestConnectionOnStartup(false); + + final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator.validate(configuration); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testMaxNumberOfPartsZero() throws Exception { + + final CMConfiguration configuration = new CMConfiguration(); + + configuration.setProductToken(UUID.randomUUID().toString()); + configuration.setDefaultFrom("DefaultFrom"); + configuration.setDefaultMaxNumberOfParts(0); + configuration.setTestConnectionOnStartup(false); + + final Set<ConstraintViolation<CMConfiguration>> constraintViolations = validator.validate(configuration); + Assert.isTrue(1 == constraintViolations.size()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMMessageTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMMessageTest.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMMessageTest.java new file mode 100644 index 0000000..d796eb9 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMMessageTest.java @@ -0,0 +1,323 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test; + +import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; +import org.apache.camel.component.cm.CMConstants; +import org.apache.camel.component.cm.CMMessage; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.Assert; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { ValidatorConfiguration.class }) +// @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +// @DisableJmx(false) +// @FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class CMMessageTest extends AbstractJUnit4SpringContextTests { + + private final PhoneNumberUtil pnu = PhoneNumberUtil.getInstance(); + private String validNumber; + + @Before + public void beforeTest() throws Exception { + validNumber = pnu.format(pnu.getExampleNumber("ES"), PhoneNumberFormat.E164); + } + + // @After + // public void afterTest() { + + /* + * GSM0338 + */ + + @Test + public void testGSM338AndLTMAXGSMMESSAGELENGTH() throws Exception { + + // 0338 and less than 160 char -> 1 part + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < CMConstants.MAX_GSM_MESSAGE_LENGTH; index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 1); + Assert.isTrue(!cmMessage.isUnicode()); + } + + @Test + public void testGSM338AndEQMAXGSMMESSAGELENGTH() throws Exception { + // 0338 and length is exactly 160 -> 1 part + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < CMConstants.MAX_GSM_MESSAGE_LENGTH; index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 1); + Assert.isTrue(!cmMessage.isUnicode()); + } + + @Test + public void testGSM338AndGTMAXGSMMESSAGELENGTH() throws Exception { + + // 0338 and length is exactly 161 -> 2 part + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < CMConstants.MAX_GSM_MESSAGE_LENGTH + 1; index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 2); + Assert.isTrue(!cmMessage.isUnicode()); + } + + @Test + public void testGSM338AndLT2MAXGSMMESSAGELENGTH() throws Exception { + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (2 * CMConstants.MAX_GSM_MESSAGE_LENGTH_PER_PART_IF_MULTIPART - 1); index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 2); + Assert.isTrue(!cmMessage.isUnicode()); + } + + @Test + public void testGSM338AndEQ2MAXGSMMESSAGELENGTH() throws Exception { + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (2 * CMConstants.MAX_GSM_MESSAGE_LENGTH_PER_PART_IF_MULTIPART); index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 2); + Assert.isTrue(!cmMessage.isUnicode()); + } + + @Test + public void testGSM338AndGT2MAXGSMMESSAGELENGTH() throws Exception { + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (2 * CMConstants.MAX_GSM_MESSAGE_LENGTH_PER_PART_IF_MULTIPART + 1); index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 3); + Assert.isTrue(!cmMessage.isUnicode()); + } + + @Test + public void testGSM338AndEQ8MAXGSMMESSAGELENGTH() throws Exception { + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (8 * CMConstants.MAX_GSM_MESSAGE_LENGTH_PER_PART_IF_MULTIPART); index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 8); + Assert.isTrue(!cmMessage.isUnicode()); + } + + @Test + public void testGSM338AndGT8MAXGSMMESSAGELENGTH() throws Exception { + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (8 * CMConstants.MAX_GSM_MESSAGE_LENGTH_PER_PART_IF_MULTIPART + 1); index++) { + message.append("a"); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 8); + Assert.isTrue(!cmMessage.isUnicode()); + } + + /* + * Unicode Messages + */ + + @Test + public void testUnicodeAndLTMAXGSMMESSAGELENGTH() throws Exception { + + String ch = "\uF400"; + + // 0338 and less than 160 char -> 1 part + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < CMConstants.MAX_UNICODE_MESSAGE_LENGTH; index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 1); + Assert.isTrue(cmMessage.isUnicode()); + } + + @Test + public void testUnicodeAndEQMAXGSMMESSAGELENGTH() throws Exception { + // 0338 and length is exactly 160 -> 1 part + + String ch = "\uF400"; + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < CMConstants.MAX_UNICODE_MESSAGE_LENGTH; index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 1); + Assert.isTrue(cmMessage.isUnicode()); + } + + @Test + public void testUnicodeAndGTMAXGSMMESSAGELENGTH() throws Exception { + + // 0338 and length is exactly 161 -> 2 part + + String ch = "\uF400"; + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < CMConstants.MAX_UNICODE_MESSAGE_LENGTH + 1; index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 2); + Assert.isTrue(cmMessage.isUnicode()); + } + + @Test + public void testUnicodeAndLT2MAXGSMMESSAGELENGTH() throws Exception { + + String ch = "\uF400"; + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (2 * CMConstants.MAX_UNICODE_MESSAGE_LENGTH_PER_PART_IF_MULTIPART - 1); index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 2); + Assert.isTrue(cmMessage.isUnicode()); + } + + @Test + public void testUnicodeAndEQ2MAXGSMMESSAGELENGTH() throws Exception { + + String ch = "\uF400"; + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (2 * CMConstants.MAX_UNICODE_MESSAGE_LENGTH_PER_PART_IF_MULTIPART); index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 2); + Assert.isTrue(cmMessage.isUnicode()); + } + + @Test + public void testUnicodeAndGT2MAXGSMMESSAGELENGTH() throws Exception { + + String ch = "\uF400"; + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (2 * CMConstants.MAX_UNICODE_MESSAGE_LENGTH_PER_PART_IF_MULTIPART + 1); index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 3); + Assert.isTrue(cmMessage.isUnicode()); + } + + @Test + public void testUnicodeAndEQ8MAXGSMMESSAGELENGTH() throws Exception { + + String ch = "\uF400"; + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (8 * CMConstants.MAX_UNICODE_MESSAGE_LENGTH_PER_PART_IF_MULTIPART); index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 8); + Assert.isTrue(cmMessage.isUnicode()); + } + + @Test + public void testUnicodeAndGT8MAXGSMMESSAGELENGTH() throws Exception { + + String ch = "\uF400"; + + StringBuffer message = new StringBuffer(); + for (int index = 0; index < (8 * CMConstants.MAX_GSM_MESSAGE_LENGTH_PER_PART_IF_MULTIPART + 1); index++) { + message.append(ch); + } + + final CMMessage cmMessage = new CMMessage(validNumber, message.toString()); + cmMessage.setUnicodeAndMultipart(CMConstants.DEFAULT_MULTIPARTS); + + Assert.isTrue(cmMessage.getMultiparts() == 8); + Assert.isTrue(cmMessage.isUnicode()); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMProxy.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMProxy.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMProxy.java new file mode 100644 index 0000000..45b88bd --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMProxy.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test; + +import org.apache.camel.component.cm.client.SMSMessage; + +/** + * Regular interface used to proxy a producer sending to the Route out to CM Direct {@link http://camel.apache.org/using-camelproxy.html} + */ +public interface CMProxy { + void send(SMSMessage smsMessage); +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMTest.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMTest.java new file mode 100644 index 0000000..e151e5a --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CMTest.java @@ -0,0 +1,375 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test; + +import java.math.BigInteger; +import java.security.SecureRandom; + +import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; +import org.apache.camel.CamelContext; +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.InvalidPayloadRuntimeException; +import org.apache.camel.Produce; +import org.apache.camel.ResolveEndpointFailedException; +import org.apache.camel.Service; +import org.apache.camel.component.cm.CMEndpoint; +import org.apache.camel.component.cm.CMProducer; +import org.apache.camel.component.cm.client.SMSMessage; +import org.apache.camel.component.cm.exceptions.HostUnavailableException; +import org.apache.camel.component.cm.exceptions.cmresponse.CMResponseException; +import org.apache.camel.component.cm.exceptions.cmresponse.InsufficientBalanceException; +import org.apache.camel.component.cm.exceptions.cmresponse.InvalidMSISDNException; +import org.apache.camel.component.cm.exceptions.cmresponse.InvalidProductTokenException; +import org.apache.camel.component.cm.exceptions.cmresponse.NoAccountFoundForProductTokenException; +import org.apache.camel.component.cm.exceptions.cmresponse.NoMessageException; +import org.apache.camel.component.cm.exceptions.cmresponse.NotPhoneNumberFoundException; +import org.apache.camel.component.cm.exceptions.cmresponse.UnknownErrorException; +import org.apache.camel.component.cm.exceptions.cmresponse.UnroutableMessageException; +import org.apache.camel.component.cm.test.mocks.cmsender.CMResponseExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.InsufficientBalanceExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.InvalidMSISDNExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.InvalidProductTokenExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.NoAccountFoundForProductTokenExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.NoMessageExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.NotPhoneNumberFoundExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.UnknownErrorExceptionSender; +import org.apache.camel.component.cm.test.mocks.cmsender.UnroutableMessageExceptionSender; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader; +import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.util.Assert; + +@RunWith(CamelSpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {CamelTestConfiguration.class }, loader = CamelSpringDelegatingTestContextLoader.class) +public class CMTest extends AbstractJUnit4SpringContextTests { + + // dependency: camel-spring-javaconfig + + @Autowired + private CamelContext camelContext; + + private SecureRandom random = new SecureRandom(); + + private final PhoneNumberUtil pnu = PhoneNumberUtil.getInstance(); + private String validNumber; + + @Produce(uri = "direct:sms") + private CMProxy cmProxy; + + @EndpointInject(uri = "mock:test") + private MockEndpoint mock; + + // private StopWatch stopWatch = new StopWatch(getClass().getSimpleName()); + + @Before + public void beforeTest() throws Exception { + mock.reset(); + camelContext.startRoute(CamelTestConfiguration.SIMPLE_ROUTE_ID); + validNumber = pnu.format(pnu.getExampleNumber("ES"), PhoneNumberFormat.E164); + } + + @After + public void afterTest() { + + try { + camelContext.stopRoute(CamelTestConfiguration.SIMPLE_ROUTE_ID); + } catch (Exception e) { + logger.error("Exception trying to stop de routes", e); + } + + // Stop all routes + // for (Route route : camelContext.getRoutes()) { + // try { + // camelContext.stopRoute(route.getId()); + // } catch (Exception e) { + // logger.error("Exception trying to stop de routes", e); + // } + // } + } + + /* + * 1. Invalid URI + */ + + @Test(expected = ResolveEndpointFailedException.class) + public void testNotRequiredProductToken() throws Throwable { + try { + String schemedUri = "cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&testConnectionOnStartup=true"; + camelContext.getEndpoint(schemedUri).start(); + } catch (Throwable t) { + throw t.getCause(); + } + + } + + @Test(expected = ResolveEndpointFailedException.class) + public void testNotRequiredDefaultFrom() throws Throwable { + try { + String schemedUri = "cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&testConnectionOnStartup=true"; + camelContext.getEndpoint(schemedUri).start(); + } catch (Throwable t) { + throw t.getCause(); + } + + } + + @Test(expected = HostUnavailableException.class) + public void testHostUnavailableException() throws Throwable { + // cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true + String schemedUri = "cm-sms://dummy.sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true"; + Service service = camelContext.getEndpoint(schemedUri).createProducer(); + service.start(); + } + + @Test(expected = ResolveEndpointFailedException.class) + public void testInvalidHostDuplicateScheme() throws Throwable { + // cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true + try { + String schemedUri = "cm-sms://https://demo.com"; + camelContext.getEndpoint(schemedUri); + } catch (Throwable t) { + throw t.getCause(); + } + } + + @Test(expected = ResolveEndpointFailedException.class) + public void testInvalidUriEndpoint() throws Throwable { + // cm-sms://sgw01.cm.nl/gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true + String noHostUri = "cm-sms://gateway.ashx?defaultFrom=MyBusiness&defaultMaxNumberOfParts=8&productToken=ea723fd7-da81-4826-89bc-fa7144e71c40&testConnectionOnStartup=true"; + camelContext.getEndpoint(noHostUri); + } + + /* + * 2. Invalid Payload + */ + + @Test(expected = RuntimeException.class) + public void testNullPayload() throws Throwable { + cmProxy.send(null); + } + + // @DirtiesContext + @Test(expected = NoAccountFoundForProductTokenException.class) + public void testAsPartOfARoute() throws Exception { + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); + cmProxy.send(smsMessage); + } + + @Test(expected = NoAccountFoundForProductTokenException.class) + public void testNoAccountFoundForProductTokenException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new NoAccountFoundForProductTokenExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); + send(producer, smsMessage); + } + + /* + * 3. CM Responses (Faking Exceptions) + */ + + @Test(expected = CMResponseException.class) + public void testCMResponseException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new CMResponseExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = InsufficientBalanceException.class) + public void testInsufficientBalanceException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new InsufficientBalanceExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = InvalidMSISDNException.class) + public void testInvalidMSISDNException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new InvalidMSISDNExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = InvalidProductTokenException.class) + public void testInvalidProductTokenException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new InvalidProductTokenExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = NoMessageException.class) + public void testNoMessageException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new NoMessageExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = NotPhoneNumberFoundException.class) + public void testNotPhoneNumberFoundException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new NotPhoneNumberFoundExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = UnknownErrorException.class) + public void testUnknownErrorException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new UnknownErrorExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = UnroutableMessageException.class) + public void testUnroutableMessageException() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + CMProducer producer = endpoint.createProducer(); + producer.setSender(new UnroutableMessageExceptionSender()); + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateUnicodeMessage(), validNumber, null); + send(producer, smsMessage); + } + + @Test(expected = UnsupportedOperationException.class) + public void testCMEndpointIsForProducing() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + endpoint.createConsumer(null); + } + + @Test + public void testCMEndpointGetHost() throws Exception { + + // Change sending strategy + CMEndpoint endpoint = (CMEndpoint) camelContext.getEndpoint(applicationContext.getBean(CamelTestConfiguration.class).getUri()); + Assert.isTrue(endpoint.getHost().equals(applicationContext.getEnvironment().getRequiredProperty("cm.url"))); + } + + @Test(expected = InvalidPayloadRuntimeException.class) + public void testSendInvalidPayload() throws Exception { + + // Body + final SMSMessage smsMessage = new SMSMessage(generateIdAsString(), generateGSM0338Message(), null, null); + cmProxy.send(smsMessage); + } + + /* + * CMMessages + */ + + // @Test(expected = RuntimeException.class) + // public void testSkel() throws Exception { + + // mock.expectedMessageCount(1); + // + // // Body + // final SMSMessage smsMessage = new SMSMessage("Hello CM", validNumber); + // cmProxy.send(smsMessage); + // + // mock.assertIsSatisfied(); + // } + + private String generateUnicodeMessage() { + String ch = "\uF400"; + return generateRandomLengthMessageByChar(ch); + } + + private String generateGSM0338Message() { + String ch = "a"; + return generateRandomLengthMessageByChar(ch); + } + + private String generateRandomLengthMessageByChar(String ch) { + // random Length + int msgLength = (int) (Math.random() * 2000); + StringBuffer message = new StringBuffer(); + for (int index = 0; index < msgLength; index++) { + message.append(ch); + } + return message.toString(); + } + + // + private String generateIdAsString() { + return new BigInteger(130, random).toString(32); + } + + private static void send(CMProducer producer, SMSMessage smsMessage) throws Exception { + Exchange exchange = producer.getEndpoint().createExchange(); + exchange.getIn().setBody(smsMessage); + producer.process(exchange); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CamelTestConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CamelTestConfiguration.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CamelTestConfiguration.java new file mode 100644 index 0000000..170ea6d --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/CamelTestConfiguration.java @@ -0,0 +1,110 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.util.Assert; +import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; + +/** + * Builds a SimpleRoute to send a message to CM GW and CM Uri is built based on + * properties in a file. + */ +@Configuration("cmConfig") +@PropertySource("classpath:/cm-smsgw.properties") +public class CamelTestConfiguration extends SingleRouteCamelConfiguration { + + public static final String SIMPLE_ROUTE_ID = "simple-route"; + + private String uri; + + @Override + public RouteBuilder route() { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + + Assert.hasLength(uri); + + log.debug("CM Component is an URI based component\nCM URI: {}", uri); + + // Route definition + from("direct:sms").to(uri).to("mock:test") + .routeId(SIMPLE_ROUTE_ID); + + } + }; + } + + @Bean + public LocalValidatorFactoryBean getValidatorFactory() { + final LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); + localValidatorFactoryBean.getValidationPropertyMap() + .put("hibernate.validator.fail_fast", "true"); + return localValidatorFactoryBean; + } + + /** + * Build the URI of the CM Component based on Environmental properties + */ + @Override + public final void setApplicationContext( + final ApplicationContext applicationContext) { + + super.setApplicationContext(applicationContext); + + final Environment env = applicationContext.getEnvironment(); + + final String host = env.getRequiredProperty("cm.url"); + final String productTokenString = env + .getRequiredProperty("cm.product-token"); + final String sender = env.getRequiredProperty("cm.default-sender"); + + final StringBuffer cmUri = new StringBuffer("cm-sms:" + host) + .append("?productToken=").append(productTokenString); + if (sender != null && !sender.isEmpty()) { + cmUri.append("&defaultFrom=").append(sender); + } + + // Defaults to false + final Boolean testConnectionOnStartup = Boolean.parseBoolean( + env.getProperty("cm.testConnectionOnStartup", "false")); + if (testConnectionOnStartup) { + cmUri.append("&testConnectionOnStartup=") + .append(testConnectionOnStartup.toString()); + } + + // Defaults to 8 + final Integer defaultMaxNumberOfParts = Integer + .parseInt(env.getProperty("defaultMaxNumberOfParts", "8")); + cmUri.append("&defaultMaxNumberOfParts=") + .append(defaultMaxNumberOfParts.toString()); + + uri = cmUri.toString(); + } + + public String getUri() { + return uri; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/SMSMessageTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/SMSMessageTest.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/SMSMessageTest.java new file mode 100644 index 0000000..8d653d3 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/SMSMessageTest.java @@ -0,0 +1,183 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test; + +import java.util.Set; + +import javax.validation.ConstraintViolation; +import javax.validation.Validator; + +import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; +import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; +import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource; +import org.apache.camel.component.cm.client.SMSMessage; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.Assert; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {ValidatorConfiguration.class }) +// @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +// @DisableJmx(false) +// @FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class SMSMessageTest extends AbstractJUnit4SpringContextTests { + + @Autowired + private Validator validator; + + private final PhoneNumberUtil pnu = PhoneNumberUtil.getInstance(); + private String validNumber; + + @Before + public void beforeTest() throws Exception { + + validNumber = pnu.format(pnu.getExampleNumber("ES"), PhoneNumberFormat.E164); + } + + // @After + // public void afterTest() { + + @Test + public void testSMSMessageConstructor() throws Throwable { + + // Coverage ;) + SMSMessage message = new SMSMessage(null, null); + Assert.isNull(message.getMessage()); + Assert.isNull(message.getPhoneNumber()); + + message = new SMSMessage("idAsString", null, null, "MySelf"); + Assert.isTrue(message.getId().equals("idAsString")); + Assert.isTrue(message.getFrom().equals("MySelf")); + } + + @Test + public void testNullMessageField() throws Exception { + + final SMSMessage m = new SMSMessage(null, validNumber); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testNullPhoneNumber() throws Exception { + + final SMSMessage m = new SMSMessage("Hello world!", null); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testDynamicFromFieldMaxLength() throws Exception { + + String dynamicFrom = "messagelengthgreaterthan12"; + + final SMSMessage m = new SMSMessage("idAsString", "Hello World", validNumber, dynamicFrom); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testDynamicFromFieldZeroLength() throws Exception { + + String zeroLengthDynamicFrom = ""; + + final SMSMessage m = new SMSMessage("idAsString", "Hello World", validNumber, zeroLengthDynamicFrom); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testIdAsStringMaxLength() throws Exception { + + String idAsString = "thisistheidastringlengthgreaterthan32"; + + final SMSMessage m = new SMSMessage(idAsString, "Hello World", validNumber, "MySelf"); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testIdAsStringFieldZeroLength() throws Exception { + + String zeroLengthIdAsString = ""; + + final SMSMessage m = new SMSMessage(zeroLengthIdAsString, "Hello World", validNumber, "MySelf"); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testE164NullNumberIsInValid() throws Exception { + + final String phoneNumber = null; + final SMSMessage m = new SMSMessage("Hello world!", phoneNumber); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testE164IsValid() throws Exception { + + final SMSMessage m = new SMSMessage("Hello world!", validNumber); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(0 == constraintViolations.size()); + } + + @Test + public void testE164NoPlusSignedNumberIsInvalid() throws Exception { + + final String phoneNumber = "34600000000"; + final SMSMessage m = new SMSMessage("Hello world!", phoneNumber); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testE164NoPlusSignedNumberBut00IsInvalid() throws Exception { + + final String phoneNumber = new PhoneNumber().setCountryCodeSource(CountryCodeSource.FROM_NUMBER_WITHOUT_PLUS_SIGN).setNationalNumber(0034600000000).toString(); + final SMSMessage m = new SMSMessage("Hello world!", phoneNumber); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } + + @Test + public void testE164NumberWithPlusSignIsInvalid() throws Exception { + + final String phoneNumber = "+34 600 00 00 00"; + final SMSMessage m = new SMSMessage("Hello world!", phoneNumber); + + final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m); + Assert.isTrue(1 == constraintViolations.size()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/ValidatorConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/ValidatorConfiguration.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/ValidatorConfiguration.java new file mode 100644 index 0000000..9e8779e --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/ValidatorConfiguration.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; + +/** + * Builds a SimpleRoute to send a message to CM GW and CM Uri is built based on properties in a file. + */ +@Configuration("smsConfig") +public class ValidatorConfiguration { + + @Bean + public LocalValidatorFactoryBean getValidatorFactory() { + final LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); + localValidatorFactoryBean.getValidationPropertyMap().put("hibernate.validator.fail_fast", "true"); + return localValidatorFactoryBean; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/CMResponseExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/CMResponseExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/CMResponseExceptionSender.java new file mode 100644 index 0000000..fe23ae9 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/CMResponseExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.CMResponseException; + +public class CMResponseExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new CMResponseException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InsufficientBalanceExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InsufficientBalanceExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InsufficientBalanceExceptionSender.java new file mode 100644 index 0000000..413df91 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InsufficientBalanceExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.InsufficientBalanceException; + +public class InsufficientBalanceExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new InsufficientBalanceException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidMSISDNExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidMSISDNExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidMSISDNExceptionSender.java new file mode 100644 index 0000000..09107d5 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidMSISDNExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.InvalidMSISDNException; + +public class InvalidMSISDNExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new InvalidMSISDNException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidProductTokenExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidProductTokenExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidProductTokenExceptionSender.java new file mode 100644 index 0000000..102cbf4 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/InvalidProductTokenExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.InvalidProductTokenException; + +public class InvalidProductTokenExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new InvalidProductTokenException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoAccountFoundForProductTokenExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoAccountFoundForProductTokenExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoAccountFoundForProductTokenExceptionSender.java new file mode 100644 index 0000000..7fb4c2b --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoAccountFoundForProductTokenExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.NoAccountFoundForProductTokenException; + +public class NoAccountFoundForProductTokenExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new NoAccountFoundForProductTokenException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoMessageExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoMessageExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoMessageExceptionSender.java new file mode 100644 index 0000000..6e27dcf --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NoMessageExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.NoMessageException; + +public class NoMessageExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new NoMessageException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NotPhoneNumberFoundExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NotPhoneNumberFoundExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NotPhoneNumberFoundExceptionSender.java new file mode 100644 index 0000000..162ef38 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/NotPhoneNumberFoundExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.NotPhoneNumberFoundException; + +public class NotPhoneNumberFoundExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new NotPhoneNumberFoundException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnknownErrorExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnknownErrorExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnknownErrorExceptionSender.java new file mode 100644 index 0000000..33e4565 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnknownErrorExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.UnknownErrorException; + +public class UnknownErrorExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new UnknownErrorException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnroutableMessageExceptionSender.java ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnroutableMessageExceptionSender.java b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnroutableMessageExceptionSender.java new file mode 100644 index 0000000..3657ac7 --- /dev/null +++ b/components/camel-cm-sms/src/test/java/org/apache/camel/component/cm/test/mocks/cmsender/UnroutableMessageExceptionSender.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.cm.test.mocks.cmsender; + +import org.apache.camel.component.cm.CMMessage; +import org.apache.camel.component.cm.CMSender; +import org.apache.camel.component.cm.exceptions.cmresponse.UnroutableMessageException; + +public class UnroutableMessageExceptionSender implements CMSender { + + @Override + public void send(CMMessage cmMessage) { + throw new UnroutableMessageException(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm-sms/src/test/resources/cm-smsgw.properties ---------------------------------------------------------------------- diff --git a/components/camel-cm-sms/src/test/resources/cm-smsgw.properties b/components/camel-cm-sms/src/test/resources/cm-smsgw.properties new file mode 100644 index 0000000..9393fa9 --- /dev/null +++ b/components/camel-cm-sms/src/test/resources/cm-smsgw.properties @@ -0,0 +1,28 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +# DefaultSender +cm.default-sender=MyBusiness + +# CM URL +# https://dashboard.onlinesmsgateway.com/docs#send-a-message-send-a-message +cm.url=sgw01.cm.nl/gateway.ashx + +# UUID as STRING +cm.product-token=ea723fd7-da81-4826-89bc-fa7144e71c40 + +cm.testConnectionOnStartup=true \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm/README.md ---------------------------------------------------------------------- diff --git a/components/camel-cm/README.md b/components/camel-cm/README.md deleted file mode 100644 index 63f9059..0000000 --- a/components/camel-cm/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# camel-cm - -[Camel component](http://camel.apache.org/components.html) for the [CM SMS Gateway](https://www.cmtelecom.com). - -It allows to integrate [CM SMS API](https://dashboard.onlinesmsgateway.com/docs) in an application as a camel component. - -You must have a valid account. More information are available at [CM Telecom](https://www.cmtelecom.com/support). - -### URI Format - -``` -cm://sgw01.cm.nl/gateway.ashx?defaultFrom=DefaultSender&defaultMaxNumberOfParts=8&productToken=2fb82162-754c-4c1b-806d-9cb7efd677f4 -``` - - -### Endpoint Options - -CM endpoints act like a **producer** and support the following options. - -| Name | Default Value | Description | -| ------------- | ------------- | ------------- | -| productToken |*none* |**Required**. UUID as String. This is the product token that was sent to you by email. Example: 'de7c7df3-81ca-4d1e-863d-95a252120321'| -| defaultFrom | *none* |**Required**. This is the default sender name, to be included in each SMSMessage instance not providing one. The maximum length is 11 characters.| -| defaultMaxNumberOfParts | 8 | If it is a [multipart message](https://dashboard.onlinesmsgateway.com/docs#send-a-message-multipart) forces the max number of parts to be sent. <p>The gateway will first check if a message is larger than 160 characters, if so, the message will be cut into multiple 153 characters parts limited by these parameters whether the message is [GSM 0038 encodeable](https://en.wikipedia.org/wiki/GSM_03.38). <p>Otherwise, The gateway will check if a message is larger than 70 characters, if so, the message will be cut into multiple 67 characters parts to a maximum of this parameter.| -| testConnectionOnStartup | false | This ensures that Camel is not started with failed connections cause an exception is thrown on startup. | - -### Tests - -Tests provided so far show a valid [Spring Configuration](https://github.com/oalles/camel-cm/blob/master/src/test/java/org/apache/camel/component/cm/test/TestConfiguration.java). Notice that CM Component URI is built from properties in a [file](https://github.com/oalles/camel-cm/blob/master/src/test/resources/cm-smsgw.properties). - -### Sample of Usage -You can try [this project](https://github.com/oalles/camel-cm-sample) to see how camel-cm can be integrated in a camel route. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/58515451/components/camel-cm/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-cm/pom.xml b/components/camel-cm/pom.xml deleted file mode 100644 index 9d010f4..0000000 --- a/components/camel-cm/pom.xml +++ /dev/null @@ -1,105 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor - license agreements. See the NOTICE file distributed with this work for additional - information regarding copyright ownership. The ASF licenses this file to - You 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. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.camel</groupId> - <artifactId>components</artifactId> - <version>2.18-SNAPSHOT</version> - </parent> - - <artifactId>camel-cm</artifactId> - <packaging>bundle</packaging> - - <name>Camel :: CM</name> - <description>Camel CM Component</description> - - <properties> - <camel.osgi.export.pkg>org.apache.camel.component.cm.*</camel.osgi.export.pkg> - <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=cm</camel.osgi.export.service> - <httpclient>${httpclient4-version}</httpclient> - <jsoup-version>1.8.3</jsoup-version> - <libphonenumber-version>7.2.7</libphonenumber-version> - <commons-validator-version>1.5.0</commons-validator-version> - </properties> - - <dependencies> - - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - </dependency> - - <dependency> - <groupId>com.googlecode.libphonenumber</groupId> - <artifactId>libphonenumber</artifactId> - <version>${libphonenumber-version}</version> - </dependency> - - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient-osgi</artifactId> - <version>${httpclient}</version> - </dependency> - <dependency> - <groupId>org.jsoup</groupId> - <artifactId>jsoup</artifactId> - <version>${jsoup-version}</version> - </dependency> - - <dependency> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - <version>${validation-api-version}</version> - </dependency> - <dependency> - <groupId>javax.el</groupId> - <artifactId>javax.el-api</artifactId> - <version>${javax.el-api-version}</version> - </dependency> - <dependency> - <groupId>commons-validator</groupId> - <artifactId>commons-validator</artifactId> - <version>${commons-validator-version}</version> - </dependency> - - <!-- test dependencies --> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test-spring</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-spring-javaconfig</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-validator</artifactId> - <version>${hibernate-validator-version}</version> - <scope>test</scope> - </dependency> - </dependencies> -</project>