Java tutorial
/** * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.md file. */ package org.mule.modules.sugarcrm.automation.system; import java.util.Properties; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; import org.mule.api.ConnectionException; import org.mule.modules.sugarcrm.api.SugarCrmClient; import org.mule.modules.sugarcrm.api.SugarCrmClientSoap; import org.mule.modules.sugarcrm.exception.InvalidLoginException; import org.mule.modules.sugarcrm.util.CryptoUtils; import org.mule.tools.devkit.ctf.configuration.util.ConfigurationUtils; import org.mule.tools.devkit.ctf.exceptions.ConfigurationLoadingFailedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.sugarcrm.sugarcrm.EntryValue; import com.sugarcrm.sugarcrm.LoginRequestType; import com.sugarcrm.sugarcrm.UserAuth; public class ConfigTestCases { private static final Logger logger = LoggerFactory.getLogger(ConfigTestCases.class); @Rule public TestName name = new TestName(); private SugarCrmClient client; private Properties credentials; private String username; private String password; private String endpoint; @Before public void setUp() throws ConnectionException, ConfigurationLoadingFailedException { logger.debug("\n\n++++++++++++++++++++ TEST {} ++++++++++++++++++++\n", name.getMethodName()); credentials = ConfigurationUtils.getAutomationCredentialsProperties(); username = credentials.getProperty("config.username"); password = CryptoUtils.getMd5(credentials.getProperty("config.password")); endpoint = credentials.getProperty("config.endpoint"); client = new SugarCrmClientSoap(endpoint); } @Test public void shouldLoggedCorrectly() throws ConnectionException { LoginRequestType request = createRequestLogin(username, password); EntryValue response = client.login(request).getReturn(); Assert.assertNotNull(response); Assert.assertNotNull(response.getId()); Assert.assertFalse("".equals(response.getId())); logger.trace("response-login: {}", ReflectionToStringBuilder.toString(response)); } @Test(expected = InvalidLoginException.class) public void shouldFailLogin() { LoginRequestType request = createRequestLogin("XXX", "INVALID"); client.login(request); } protected LoginRequestType createRequestLogin(String username, String password) { UserAuth userAuth = new UserAuth(); userAuth.setUserName(username); userAuth.setPassword(password); LoginRequestType request = new LoginRequestType(); request.setUserAuth(userAuth); request.setApplicationName("https://ctohnl0202.trial.sugarcrm.com/"); return request; } }