diff --git a/bb-email/pom.xml b/bb-email/pom.xml index 4517ea08..bcb23741 100644 --- a/bb-email/pom.xml +++ b/bb-email/pom.xml @@ -35,6 +35,10 @@ com.google.inject guice + + com.google.inject.extensions + guice-assistedinject + org.apache.commons commons-lang3 diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailClient.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailClient.java index cbf2bac4..b99965e7 100644 --- a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailClient.java +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailClient.java @@ -33,7 +33,9 @@ import org.slf4j.LoggerFactory; import com.cognifide.qa.bb.email.connector.Connector; -import com.google.inject.Inject; +import com.cognifide.qa.bb.email.connector.ConnectorFactory; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; /** * This class represents email client. @@ -49,13 +51,16 @@ public class EmailClient { private Folder folder; /** - * @param connection MailBox protocol connection. - * @param emailDataFactory Email data factory + * @param id Identification of configuration. + * @param connectionFactory Email config factory + * @param emailConfigFactory Email config factory */ - @Inject - public EmailClient(Connector connection, EmailDataFactory emailDataFactory) { - this.connection = connection; - this.emailDataFactory = emailDataFactory; + @AssistedInject + public EmailClient(@Assisted String id, ConnectorFactory connectionFactory, + EmailConfigFactory emailConfigFactory) { + EmailConfig emailConfig = emailConfigFactory.create(id); + this.connection = connectionFactory.create(id).get(); + this.emailDataFactory = new EmailDataFactory(emailConfig); } /** diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailClientFactory.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailClientFactory.java new file mode 100644 index 00000000..8243d3d0 --- /dev/null +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailClientFactory.java @@ -0,0 +1,25 @@ +/*- + * #%L + * Bobcat + * %% + * Copyright (C) 2016 Cognifide Ltd. + * %% + * 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. + * #L% + */ +package com.cognifide.qa.bb.email; + +public interface EmailClientFactory { + + EmailClient create(String id); +} diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailConfig.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailConfig.java new file mode 100644 index 00000000..a9c81155 --- /dev/null +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailConfig.java @@ -0,0 +1,53 @@ +/*- + * #%L + * Bobcat + * %% + * Copyright (C) 2016 Cognifide Ltd. + * %% + * 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. + * #L% + */ +package com.cognifide.qa.bb.email; + +import java.util.Collections; +import java.util.Map; + +import org.apache.commons.lang3.text.StrSubstitutor; + +import com.cognifide.qa.bb.email.constants.EmailConfigKeys; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; +import com.google.inject.name.Names; + +public class EmailConfig { + + private final Map map; + private final Injector injector; + + @AssistedInject + public EmailConfig(@Assisted String id, Injector injector) { + this.map = Collections.singletonMap(EmailConfigKeys.ID, id); + this.injector = injector; + } + + public String getParameter(String name) { + return getParameter(String.class, name); + } + + public T getParameter(Class type, String name) { + String realId = StrSubstitutor.replace(name, map); + return injector.getInstance(Key.get(type, Names.named(realId))); + } +} diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailConfigFactory.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailConfigFactory.java new file mode 100644 index 00000000..55fe21cd --- /dev/null +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailConfigFactory.java @@ -0,0 +1,25 @@ +/*- + * #%L + * Bobcat + * %% + * Copyright (C) 2016 Cognifide Ltd. + * %% + * 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. + * #L% + */ +package com.cognifide.qa.bb.email; + +public interface EmailConfigFactory { + + EmailConfig create(String id); +} diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailDataFactory.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailDataFactory.java index 313a2bb3..64a6e10e 100644 --- a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailDataFactory.java +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailDataFactory.java @@ -36,7 +36,6 @@ import com.cognifide.qa.bb.email.connector.EmailException; import com.cognifide.qa.bb.email.constants.EmailConfigKeys; import com.google.inject.Inject; -import com.google.inject.name.Named; /** * This class creates EmailData. @@ -45,11 +44,11 @@ public final class EmailDataFactory { private static final Logger LOGGER = LoggerFactory.getLogger(EmailDataFactory.class); - private final Pattern addressPattern; + private Pattern addressPattern; @Inject - public EmailDataFactory( - @Named(EmailConfigKeys.EMAIL_ADDRESS_PATTERN) String addressPatternString) { + public EmailDataFactory(EmailConfig emailConfig) { + String addressPatternString = emailConfig.getParameter(EmailConfigKeys.EMAIL_ADDRESS_PATTERN); this.addressPattern = Pattern.compile(addressPatternString); } diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailModule.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailModule.java index 0632846d..6f5c347a 100644 --- a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailModule.java +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailModule.java @@ -19,9 +19,9 @@ */ package com.cognifide.qa.bb.email; -import com.cognifide.qa.bb.email.connector.Connector; -import com.cognifide.qa.bb.email.connector.ConnectorProvider; +import com.cognifide.qa.bb.email.connector.ConnectorFactory; import com.google.inject.AbstractModule; +import com.google.inject.assistedinject.FactoryModuleBuilder; /** * Install this module to enable email service. After installation, following email protocols will @@ -36,6 +36,9 @@ public class EmailModule extends AbstractModule { @Override protected void configure() { - bind(Connector.class).toProvider(ConnectorProvider.class); + install(new FactoryModuleBuilder().build(ConnectorFactory.class)); + install(new FactoryModuleBuilder().build(EmailConfigFactory.class)); + install(new FactoryModuleBuilder().build(EmailClientFactory.class)); + install(new FactoryModuleBuilder().build(EmailSenderFactory.class)); } } diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailSender.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailSender.java index cd49f245..6d49fe65 100644 --- a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailSender.java +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailSender.java @@ -25,9 +25,9 @@ import com.cognifide.qa.bb.email.connector.EmailException; import com.cognifide.qa.bb.email.constants.EmailConfigKeys; -import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.inject.name.Named; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; /** * Simple class for sending emails. It uses org.apache.commons.mail library. @@ -35,26 +35,26 @@ @Singleton public class EmailSender { - @Inject - @Named(EmailConfigKeys.EMAIL_USERNAME) private String username; - @Inject - @Named(EmailConfigKeys.EMAIL_PASSWORD) private String password; - @Inject - @Named(EmailConfigKeys.SMTP_SERVER_ADDRESS) private String smtpServer; - @Inject - @Named(EmailConfigKeys.SMTP_SERVER_PORT) private int smtpPort; - @Inject - @Named(EmailConfigKeys.SMTP_SERVER_SECURE) private boolean secure; + @AssistedInject + public EmailSender(@Assisted String id, EmailConfigFactory factory) { + EmailConfig emailConfig = factory.create(id); + this.username = emailConfig.getParameter(EmailConfigKeys.EMAIL_USERNAME); + this.password = emailConfig.getParameter(EmailConfigKeys.EMAIL_PASSWORD); + this.smtpServer = emailConfig.getParameter(EmailConfigKeys.SMTP_SERVER_ADDRESS); + this.smtpPort = emailConfig.getParameter(Integer.class, EmailConfigKeys.SMTP_SERVER_PORT); + this.secure = emailConfig.getParameter(Boolean.class, EmailConfigKeys.SMTP_SERVER_SECURE); + } + public void sendEmail(final EmailData emailData) { try { Email email = new SimpleEmail(); diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailSenderFactory.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailSenderFactory.java new file mode 100644 index 00000000..f97f5009 --- /dev/null +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/EmailSenderFactory.java @@ -0,0 +1,25 @@ +/*- + * #%L + * Bobcat + * %% + * Copyright (C) 2016 Cognifide Ltd. + * %% + * 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. + * #L% + */ +package com.cognifide.qa.bb.email; + +public interface EmailSenderFactory { + + EmailSender create(String id); +} diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorConfig.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorConfig.java index f49503d5..d9091d98 100644 --- a/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorConfig.java +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorConfig.java @@ -19,37 +19,32 @@ */ package com.cognifide.qa.bb.email.connector; +import com.cognifide.qa.bb.email.EmailConfig; import com.cognifide.qa.bb.email.constants.EmailConfigKeys; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.google.inject.name.Named; /** * This class configures email connector using data from property file. */ -@Singleton public class ConnectorConfig { - @Inject - @Named(EmailConfigKeys.EMAIL_USERNAME) private String username; - @Inject - @Named(EmailConfigKeys.EMAIL_PASSWORD) private String password; - @Inject - @Named(EmailConfigKeys.EMAIL_SERVER_PORT) private int port; - @Inject - @Named(EmailConfigKeys.EMAIL_FOLDER_NAME) private String folderName; - @Inject - @Named(EmailConfigKeys.EMAIL_SERVER_ADDRESS) private String server; + public ConnectorConfig(EmailConfig emailConfig) { + this.username = emailConfig.getParameter(EmailConfigKeys.EMAIL_USERNAME); + this.password = emailConfig.getParameter(EmailConfigKeys.EMAIL_PASSWORD); + this.port = emailConfig.getParameter(Integer.class, EmailConfigKeys.EMAIL_SERVER_PORT); + this.folderName = emailConfig.getParameter(EmailConfigKeys.EMAIL_FOLDER_NAME); + this.server = emailConfig.getParameter(EmailConfigKeys.EMAIL_SERVER_ADDRESS); + } + /** * @return Name of inbox folder. */ diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorFactory.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorFactory.java new file mode 100644 index 00000000..29abd46e --- /dev/null +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorFactory.java @@ -0,0 +1,25 @@ +/*- + * #%L + * Bobcat + * %% + * Copyright (C) 2016 Cognifide Ltd. + * %% + * 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. + * #L% + */ +package com.cognifide.qa.bb.email.connector; + +public interface ConnectorFactory { + + ConnectorProvider create(String id); +} diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorProvider.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorProvider.java index ca9deecd..6fe7fb97 100644 --- a/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorProvider.java +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/connector/ConnectorProvider.java @@ -19,24 +19,28 @@ */ package com.cognifide.qa.bb.email.connector; +import com.cognifide.qa.bb.email.EmailConfig; +import com.cognifide.qa.bb.email.EmailConfigFactory; import com.cognifide.qa.bb.email.constants.EmailConfigKeys; -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.google.inject.name.Named; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; /** * This class is a provider of mailbox connector. */ -public class ConnectorProvider implements Provider { +public class ConnectorProvider { - @Inject private ConnectorConfig configuration; - @Inject - @Named(EmailConfigKeys.EMAIL_SERVER_PROTOCOL) private String protocol; - @Override + @AssistedInject + public ConnectorProvider(@Assisted String id, EmailConfigFactory emailConfigFactory) { + EmailConfig emailConfig = emailConfigFactory.create(id); + this.configuration = new ConnectorConfig(emailConfig); + this.protocol = emailConfig.getParameter(EmailConfigKeys.EMAIL_SERVER_PROTOCOL); + } + public Connector get() { ConnectorType type = ConnectorType.valueOf(protocol.trim().toUpperCase()); return type.getInstance(configuration); diff --git a/bb-email/src/main/java/com/cognifide/qa/bb/email/constants/EmailConfigKeys.java b/bb-email/src/main/java/com/cognifide/qa/bb/email/constants/EmailConfigKeys.java index 6c00a020..9ff92264 100644 --- a/bb-email/src/main/java/com/cognifide/qa/bb/email/constants/EmailConfigKeys.java +++ b/bb-email/src/main/java/com/cognifide/qa/bb/email/constants/EmailConfigKeys.java @@ -21,26 +21,31 @@ public final class EmailConfigKeys { - public static final String EMAIL_SERVER_ADDRESS = "email.server.address"; + public static final String EMAIL_SERVER_ADDRESS = "email.${id}.server.address"; - public static final String EMAIL_SERVER_PORT = "email.server.port"; + public static final String EMAIL_SERVER_PORT = "email.${id}.server.port"; - public static final String EMAIL_SERVER_PROTOCOL = "email.server.protocol"; + public static final String EMAIL_SERVER_PROTOCOL = "email.${id}.server.protocol"; - public static final String EMAIL_USERNAME = "email.username"; + public static final String EMAIL_USERNAME = "email.${id}.username"; - public static final String EMAIL_PASSWORD = "email.password"; + public static final String EMAIL_PASSWORD = "email.${id}.password"; - public static final String EMAIL_FOLDER_NAME = "email.folder.name"; + public static final String EMAIL_ADDRESS = "email.${id}.address"; - public static final String EMAIL_ADDRESS_PATTERN = "email.address.pattern"; + public static final String EMAIL_FOLDER_NAME = "email.${id}.folder.name"; - public static final String SMTP_SERVER_SECURE = "smtp.server.secure"; + public static final String EMAIL_ADDRESS_PATTERN = "email.${id}.address.pattern"; - public static final String SMTP_SERVER_PORT = "smtp.server.port"; + public static final String SMTP_SERVER_SECURE = "smtp.${id}.server.secure"; - public static final String SMTP_SERVER_ADDRESS = "smtp.server.address"; + public static final String SMTP_SERVER_PORT = "smtp.${id}.server.port"; - private EmailConfigKeys() {} + public static final String SMTP_SERVER_ADDRESS = "smtp.${id}.server.address"; + + public static final String ID = "id"; + + private EmailConfigKeys() { + } } diff --git a/bb-email/src/test/java/com/cognifide/qa/bb/email/EmailTest.java b/bb-email/src/test/java/com/cognifide/qa/bb/email/EmailTest.java index 66d199aa..c30dbb7a 100644 --- a/bb-email/src/test/java/com/cognifide/qa/bb/email/EmailTest.java +++ b/bb-email/src/test/java/com/cognifide/qa/bb/email/EmailTest.java @@ -33,46 +33,52 @@ import org.junit.runners.Parameterized.Parameters; import com.cognifide.qa.bb.email.helpers.EmailDataGenerator; +import com.cognifide.qa.bb.email.helpers.EmailDataGeneratorFactory; import com.cognifide.qa.bb.module.PropertiesLoaderModule; import com.google.inject.Guice; -import com.google.inject.Inject; import com.google.inject.Injector; +import com.google.inject.assistedinject.FactoryModuleBuilder; @RunWith(Parameterized.class) public class EmailTest { - private final String propertiesFileName; + private final String mailId; - @Inject private EmailClient client; - @Inject private EmailSender sender; - @Inject private EmailDataGenerator dataGenerator; - @Inject private MailServer mailServer; - public EmailTest(String propertiesFileName) { - this.propertiesFileName = propertiesFileName; + + public EmailTest(String mailId) { + this.mailId = mailId; } @Parameters public static Collection parameters() { return Arrays.asList(new Object[][]{ - {"email.imap.properties"}, - {"email.imaps.properties"}, - {"email.pop3s.properties"}, + {"imap"}, + {"imaps"}, + {"pop3"}, }); } @Before public void setUpClass() { - Injector injector = Guice.createInjector(new PropertiesLoaderModule(propertiesFileName), - new EmailModule()); + Injector injector = Guice.createInjector(new PropertiesLoaderModule("mail.properties"), + new EmailModule(), + new FactoryModuleBuilder().build(MailServerFactory.class), + new FactoryModuleBuilder().build(EmailDataGeneratorFactory.class) + ); injector.injectMembers(this); + String id = mailId; + sender = injector.getInstance(EmailSenderFactory.class).create(id); + client = injector.getInstance(EmailClientFactory.class).create(id); + mailServer = injector.getInstance(MailServerFactory.class).create(id); + dataGenerator = injector.getInstance(EmailDataGeneratorFactory.class).create(id); mailServer.start(); } diff --git a/bb-email/src/test/java/com/cognifide/qa/bb/email/MailServer.java b/bb-email/src/test/java/com/cognifide/qa/bb/email/MailServer.java index e90c3c36..093a6ae6 100644 --- a/bb-email/src/test/java/com/cognifide/qa/bb/email/MailServer.java +++ b/bb-email/src/test/java/com/cognifide/qa/bb/email/MailServer.java @@ -21,23 +21,31 @@ import java.security.Security; -import com.cognifide.qa.bb.email.connector.ConnectorConfig; -import com.google.inject.Inject; -import com.google.inject.name.Named; +import com.cognifide.qa.bb.email.constants.EmailConfigKeys; +import com.google.inject.Injector; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; import com.icegreen.greenmail.util.DummySSLSocketFactory; import com.icegreen.greenmail.util.GreenMail; public class MailServer { - @Inject - private ConnectorConfig config; + private final String username; + + private final String password; - @Inject - @Named("email.address") private String address; private GreenMail mailServer; + @AssistedInject + public MailServer(@Assisted String id, Injector injector) { + EmailConfig emailConfig = new EmailConfig(id, injector); + this.username = emailConfig.getParameter(EmailConfigKeys.EMAIL_USERNAME); + this.password = emailConfig.getParameter(EmailConfigKeys.EMAIL_PASSWORD); + this.address = emailConfig.getParameter(EmailConfigKeys.EMAIL_ADDRESS); + } + public void start() { Security.setProperty("ssl.SocketFactory.provider", DummySSLSocketFactory.class.getName()); // from javadoc @@ -49,7 +57,7 @@ public void start() { // imaps 3993 mailServer = new GreenMail(); mailServer.start(); - mailServer.setUser(address, config.getUsername(), config.getPassword()); + mailServer.setUser(address, username, password); } public void stop() { diff --git a/bb-email/src/test/java/com/cognifide/qa/bb/email/MailServerFactory.java b/bb-email/src/test/java/com/cognifide/qa/bb/email/MailServerFactory.java new file mode 100644 index 00000000..009a7774 --- /dev/null +++ b/bb-email/src/test/java/com/cognifide/qa/bb/email/MailServerFactory.java @@ -0,0 +1,25 @@ +/*- + * #%L + * Bobcat + * %% + * Copyright (C) 2016 Cognifide Ltd. + * %% + * 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. + * #L% + */ +package com.cognifide.qa.bb.email; + +public interface MailServerFactory { + + MailServer create(String id); +} diff --git a/bb-email/src/test/java/com/cognifide/qa/bb/email/helpers/EmailDataGenerator.java b/bb-email/src/test/java/com/cognifide/qa/bb/email/helpers/EmailDataGenerator.java index c9ea6ace..5aa9f1e3 100644 --- a/bb-email/src/test/java/com/cognifide/qa/bb/email/helpers/EmailDataGenerator.java +++ b/bb-email/src/test/java/com/cognifide/qa/bb/email/helpers/EmailDataGenerator.java @@ -24,10 +24,11 @@ import java.util.ArrayList; import java.util.List; +import com.cognifide.qa.bb.email.EmailConfigFactory; import com.cognifide.qa.bb.email.EmailData; -import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.inject.name.Named; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; @Singleton public class EmailDataGenerator { @@ -36,14 +37,16 @@ public class EmailDataGenerator { private static final int NUMBER_OF_BITS = 130; - @Inject - @Named("email.address") private String addressTo; - @Inject - @Named("email.address") private String addressFrom; + @AssistedInject + public EmailDataGenerator(@Assisted String id, EmailConfigFactory emailConfigFactory) { + this.addressTo = emailConfigFactory.create(id).getParameter("email.${id}.address"); + this.addressFrom = addressTo; + } + public List generateEmailData(int number) { List result = new ArrayList<>(); diff --git a/bb-email/src/test/java/com/cognifide/qa/bb/email/helpers/EmailDataGeneratorFactory.java b/bb-email/src/test/java/com/cognifide/qa/bb/email/helpers/EmailDataGeneratorFactory.java new file mode 100644 index 00000000..f4a07b17 --- /dev/null +++ b/bb-email/src/test/java/com/cognifide/qa/bb/email/helpers/EmailDataGeneratorFactory.java @@ -0,0 +1,26 @@ +/*- + * #%L + * Bobcat + * %% + * Copyright (C) 2016 Cognifide Ltd. + * %% + * 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. + * #L% + */ +package com.cognifide.qa.bb.email.helpers; + +public interface EmailDataGeneratorFactory { + + EmailDataGenerator create(String id); + +} diff --git a/bb-email/src/test/resources/email.imap.properties b/bb-email/src/test/resources/email.imap.properties deleted file mode 100644 index daf2a85e..00000000 --- a/bb-email/src/test/resources/email.imap.properties +++ /dev/null @@ -1,12 +0,0 @@ -email.username=qatest_user -email.password=P@ssw0rd -email.address=qatest_user3@localhost.pl -email.server.address=localhost -email.server.port=3143 -email.server.protocol=imap -email.folder.name=INBOX -smtp.server.address=127.0.0.1 -smtp.server.port=3025 -smtp.server.secure=false - -email.address.pattern="*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}"* diff --git a/bb-email/src/test/resources/email.imaps.properties b/bb-email/src/test/resources/email.imaps.properties deleted file mode 100644 index a598af51..00000000 --- a/bb-email/src/test/resources/email.imaps.properties +++ /dev/null @@ -1,12 +0,0 @@ -email.username=qatest_user -email.password=P@ssw0rd -email.address=qatest_user3@localhost.pl -email.server.address=localhost -email.server.port=3993 -email.server.protocol=imaps -email.folder.name=INBOX -smtp.server.address=127.0.0.1 -smtp.server.port=3025 -smtp.server.secure=false - -email.address.pattern="*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}"* diff --git a/bb-email/src/test/resources/email.pop3s.properties b/bb-email/src/test/resources/email.pop3s.properties deleted file mode 100644 index 3f7e384e..00000000 --- a/bb-email/src/test/resources/email.pop3s.properties +++ /dev/null @@ -1,12 +0,0 @@ -email.username=qatest_user -email.password=P@ssw0rd -email.address=qatest_user3@localhost.pl -email.server.address=localhost -email.server.port=3995 -email.server.protocol=pop -email.folder.name=INBOX -smtp.server.address=127.0.0.1 -smtp.server.port=3025 -smtp.server.secure=false - -email.address.pattern="*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}"* diff --git a/bb-email/src/test/resources/mail.properties b/bb-email/src/test/resources/mail.properties new file mode 100644 index 00000000..26d8f78a --- /dev/null +++ b/bb-email/src/test/resources/mail.properties @@ -0,0 +1,37 @@ +email.imap.username=qatest_user +email.imap.password=P@ssw0rd +email.imap.address=qatest_user3@localhost.pl +email.imap.server.address=localhost +email.imap.server.port=3143 +email.imap.server.protocol=imap +email.imap.folder.name=INBOX +email.imap.address.pattern="*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}"* +smtp.imap.server.address=127.0.0.1 +smtp.imap.server.port=3025 +smtp.imap.server.secure=false + +email.imaps.username=qatest_user +email.imaps.password=P@ssw0rd +email.imaps.address=qatest_user3@localhost.pl +email.imaps.server.address=localhost +email.imaps.server.port=3993 +email.imaps.server.protocol=imaps +email.imaps.folder.name=INBOX +email.imaps.address.pattern="*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}"* +smtp.imaps.server.address=127.0.0.1 +smtp.imaps.server.port=3025 +smtp.imaps.server.secure=false + +email.pop3.username=qatest_user +email.pop3.password=P@ssw0rd +email.pop3.address=qatest_user3@localhost.pl +email.pop3.server.address=localhost +email.pop3.server.port=3995 +email.pop3.server.protocol=pop +email.pop3.folder.name=INBOX +email.pop3.address.pattern="*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}"* +smtp.pop3.server.address=127.0.0.1 +smtp.pop3.server.port=3025 +smtp.pop3.server.secure=false + +