/*
* 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.stonehenge.stocktrader.mssql;
import org.apache.stonehenge.stocktrader.dal.ConfigServiceDAO;
import org.apache.stonehenge.stocktrader.dal.DAOFactory;
import org.datacontract.schemas._2004._07.trade.BSConfigResponse;
import org.datacontract.schemas._2004._07.trade.ClientConfigResponse;
import org.datacontract.schemas._2004._07.trade.ServiceLocation;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class ConfigServiceDAOImplTest {
private DAOFactory facotry;
public ConfigServiceDAO getConfigServiceDAO() {
return facotry.getConfigServiceDAO();
}
@Before
public void before() {
facotry = DAOFactory.getFacotry();
}
@Test
public void should_update_client_to_bs_when_entry_already_exists() {
assumeThat(getConfigServiceDAO().getClientConfig("JAVA_CLIENT"), notNullValue());
getConfigServiceDAO().setClientToBS("JAVA_CLIENT", "JAVA_BS");
ClientConfigResponse response = getConfigServiceDAO().getClientConfig("JAVA_CLIENT");
assertThat(response.getBSName(), equalTo("JAVA_BS"));
}
@Test
public void should_insert_value_into_client_to_bs_when_entry_doesnot_exists() {
assumeThat(getConfigServiceDAO().getClientConfig("RUBY_CLIENT").getBSName(), nullValue());
getConfigServiceDAO().setClientToBS("RUBY_CLIENT", "JAVA_BS");
ClientConfigResponse response = getConfigServiceDAO().getClientConfig("RUBY_CLIENT");
assertThat(response.getBSName(), equalTo("JAVA_BS"));
}
@Test
public void should_update_bs_to_ops_when_entry_already_exists() {
assumeThat(getConfigServiceDAO().getBSConfig("JAVA_BS"), notNullValue());
getConfigServiceDAO().setBSToOPS("JAVA_BS", "PHP_OPS");
BSConfigResponse response = getConfigServiceDAO().getBSConfig("JAVA_BS");
assertThat(response.getOPSName(), equalTo("PHP_OPS"));
}
@Test
public void should_update_bs_to_ops_when_entry_doesnot_exists() {
assumeThat(getConfigServiceDAO().getBSConfig("PHP_BS"), nullValue());
getConfigServiceDAO().setBSToOPS("PHP_BS", "PHP_OPS");
BSConfigResponse response = getConfigServiceDAO().getBSConfig("PHP_BS");
assertThat(response.getOPSName(), equalTo("PHP_OPS"));
}
@Test
public void should_update_bs_service() {
getConfigServiceDAO().setBSToOPS("RUBY_BS", "RUBY_OPS");
String serviceName = "RUBY_OPS";
String serviceUrl = "http://localhost/ruby";
getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, true);
BSConfigResponse response = getConfigServiceDAO().getBSConfig("RUBY_BS");
assertThat(response.getOPS(), equalTo(serviceUrl));
assertThat(response.getOPSName(), equalTo(serviceName));
assertThat(response.isSec(), equalTo(true));
}
@Test
public void should_insert_values_into_service() {
getConfigServiceDAO().setBSToOPS("AA_BS", "AA_OPS");
String serviceName = "AA_OPS";
String serviceUrl = "http://localhost/AA_OPS";
getConfigServiceDAO().setServiceLocation(serviceName, serviceUrl, false);
BSConfigResponse response = getConfigServiceDAO().getBSConfig("AA_BS");
assertThat(response.getOPS(), equalTo(serviceUrl));
assertThat(response.getOPSName(), equalTo(serviceName));
assertThat(response.isSec(), equalTo(false));
}
}