First JUnit tests for OpensyncExternalIntegrationCloud

This commit is contained in:
Mike Hansen
2020-07-10 16:24:26 -04:00
parent 3b5701f930
commit 4a516c26d2
2 changed files with 485 additions and 52 deletions

View File

@@ -432,7 +432,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
apProfile.setDetails(apNetworkConfig);
apProfile = profileServiceInterface.create(apProfile);
apProfile = profileServiceInterface.update(apProfile);
apNetworkConfig = (ApNetworkConfiguration) apProfile.getDetails();
@@ -623,7 +623,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
CustomerFirmwareTrackRecord custFwTrackRecord = firmwareServiceInterface
.getCustomerFirmwareTrackRecord(ce.getCustomerId());
long trackRecordId = 0;
long trackRecordId = -1;
if (custFwTrackRecord != null) {
trackSettings = custFwTrackRecord.getSettings();
trackRecordId = custFwTrackRecord.getTrackRecordId();
@@ -637,8 +637,16 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
// the default version for the cloud, then download and
// flash the firmware before proceeding.
// then return;
FirmwareTrackRecord fwTrackRecord = null;
if (trackRecordId == -1) {
// take the default
fwTrackRecord = firmwareServiceInterface.getFirmwareTrackByName(FirmwareTrackRecord.DEFAULT_TRACK_NAME);
FirmwareTrackRecord fwTrackRecord = firmwareServiceInterface.getFirmwareTrackById(trackRecordId);
} else {
// there must be a customer one
fwTrackRecord = firmwareServiceInterface.getFirmwareTrackById(trackRecordId);
}
if (fwTrackRecord != null) {
List<FirmwareTrackAssignmentDetails> fwTrackAssignmentDetails = firmwareServiceInterface
@@ -1475,7 +1483,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
int indexOfBssid = -1;
if (activeBssidsStatus != null) {
statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails();
for (ActiveBSSID activeBSSID : statusDetails.getActiveBSSIDs()) {
for (ActiveBSSID activeBSSID : ((ActiveBSSIDs) activeBssidsStatus.getDetails()).getActiveBSSIDs()) {
if (activeBSSID.getRadioType().equals(radioType)) {
ssidStatistics.setBssid(new MacAddress(activeBSSID.getBssid()));
// ssid value, in case not in stats, else will take
@@ -1880,7 +1888,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
}
activeBssidsStatus.setDetails(statusDetails);
if (!statusDetails.equals((ActiveBSSIDs) statusServiceInterface
.getOrNull(customerId, equipmentId, StatusDataType.ACTIVE_BSSIDS).getDetails())) {
activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus);
@@ -1903,15 +1911,15 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
.getDetails();
Map<RadioType, Integer> clientsPerRadioType = new EnumMap<>(RadioType.class);
statusDetails = (ActiveBSSIDs) activeBssidsStatus.getDetails();
for (ActiveBSSID bssid : statusDetails.getActiveBSSIDs()) {
int numConnectedForBssid = bssid.getNumDevicesConnected();
if (clientsPerRadioType.containsKey(bssid.getRadioType()) && clientsPerRadioType.get(bssid.getRadioType()) != null) {
if (clientsPerRadioType.containsKey(bssid.getRadioType())
&& clientsPerRadioType.get(bssid.getRadioType()) != null) {
numConnectedForBssid += clientsPerRadioType.get(bssid.getRadioType());
}
Integer numClientsPerRadioType = clientsPerRadioType.put(bssid.getRadioType(),
numConnectedForBssid);
Integer numClientsPerRadioType = clientsPerRadioType.put(bssid.getRadioType(), numConnectedForBssid);
LOG.debug("Upgrade numClients for RadioType {} to {} on AP {}", bssid.getRadioType(),
numClientsPerRadioType, apId);
}
@@ -1928,7 +1936,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
@Override
public void wifiRadioStatusDbTableUpdate(List<OpensyncAPRadioState> radioStateTables, String apId) {
LOG.debug("Received Wifi_Radio_State table update for AP {}", apId);
OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
@@ -1952,10 +1959,10 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
return;
}
boolean eqptUpdate = false;
ApElementConfiguration apElementConfiguration = ((ApElementConfiguration) ce.getDetails());
Status protocolStatus = null;
EquipmentProtocolStatusData protocolStatusData = null;
for (OpensyncAPRadioState radioState : radioStateTables) {
@@ -1964,30 +1971,19 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
continue;
}
Set<Integer> allowedChannels = radioState.getAllowedChannels();
List<Integer> oldAllowedChannels = apElementConfiguration.getRadioMap().get(radioState.getFreqBand()).getAllowedChannels();
Set<Integer> oldAllowedChannelSet = new HashSet<>();
if (oldAllowedChannels != null) {
oldAllowedChannelSet = new HashSet<>(oldAllowedChannels);
}
if (allowedChannels != null && !allowedChannels.equals(oldAllowedChannelSet)) {
eqptUpdate = true;
if (radioState.getAllowedChannels() != null) {
apElementConfiguration.getRadioMap().get(radioState.getFreqBand())
.setAllowedChannels(new ArrayList<>(allowedChannels));
.setAllowedChannels(new ArrayList<>(radioState.getAllowedChannels()));
LOG.debug("Updated AllowedChannels from Wifi_Radio_State table change for AP {}", apId);
}
if (radioState.getTxPower() > 0) {
AutoOrManualValue oldEirpTxPower = apElementConfiguration.getRadioMap().get(radioState.getFreqBand()).getEirpTxPower();
if (oldEirpTxPower == null || oldEirpTxPower.isAuto() ||
(!oldEirpTxPower.isAuto() && Integer.valueOf(oldEirpTxPower.getValue()) != radioState.getTxPower())) {
eqptUpdate = true;
apElementConfiguration.getRadioMap().get(radioState.getFreqBand())
.setEirpTxPower(AutoOrManualValue.createManualInstance(radioState.getTxPower()));
LOG.debug("Updated TxPower from Wifi_Radio_State table change for AP {}", apId);
}
apElementConfiguration.getRadioMap().get(radioState.getFreqBand())
.setEirpTxPower(AutoOrManualValue.createManualInstance(radioState.getTxPower()));
LOG.debug("Updated TxPower from Wifi_Radio_State table change for AP {}", apId);
}
StateSetting state = StateSetting.disabled;
@@ -1997,52 +1993,58 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
if (!apElementConfiguration.getAdvancedRadioMap().get(radioState.getFreqBand()).getRadioAdminState()
.equals(state)) {
eqptUpdate = true;
// only update if changed
apElementConfiguration.getAdvancedRadioMap().get(radioState.getFreqBand()).setRadioAdminState(state);
LOG.debug("Updated RadioAdminState from Wifi_Radio_State table change for AP {}", apId);
}
protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL);
if (protocolStatus != null) {
EquipmentProtocolStatusData protocolStatusData = (EquipmentProtocolStatusData) protocolStatus
.getDetails();
protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails();
if (!protocolStatusData.getReportedCC()
.equals(CountryCode.valueOf(radioState.getCountry().toLowerCase()))) {
protocolStatusData.setReportedCC(CountryCode.valueOf(radioState.getCountry().toLowerCase()));
protocolStatus.setDetails(protocolStatusData);
} else {
protocolStatusData = null; // no change we will ignore at
// the end
protocolStatus = null; // no change we will ignore at
// the end
}
}
}
Equipment ceNew = equipmentServiceInterface.getByInventoryIdOrNull(apId);
if (ceNew == null) {
LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Equipment for AP {}", apId);
return;
}
if (eqptUpdate) {
((ApElementConfiguration) ceNew.getDetails()).setRadioMap(apElementConfiguration.getRadioMap());
((ApElementConfiguration) ceNew.getDetails()).setAdvancedRadioMap(apElementConfiguration.getAdvancedRadioMap());
try {
equipmentServiceInterface.update(ceNew);
} catch (DsConcurrentModificationException e) {
LOG.debug("Equipment reference changed, update instance and retry.", e.getMessage());
ceNew = equipmentServiceInterface.getByInventoryIdOrNull(apId);
ceNew.setDetails(apElementConfiguration);
ceNew = equipmentServiceInterface.update(ceNew);
}
}
if (protocolStatus != null) {
statusServiceInterface.update(protocolStatus);
}
ce = equipmentServiceInterface.getByInventoryIdOrNull(apId);
if (ce == null) {
LOG.debug("wifiRadioStatusDbTableUpdate::Cannot get Equipment for AP {}", apId);
return;
}
try {
if (!apElementConfiguration.equals(((ApElementConfiguration) ce.getDetails()))) {
((ApElementConfiguration) ce.getDetails()).setRadioMap(apElementConfiguration.getRadioMap());
((ApElementConfiguration) ce.getDetails())
.setAdvancedRadioMap(apElementConfiguration.getAdvancedRadioMap());
apElementConfiguration = (ApElementConfiguration) ce.getDetails();
ce = equipmentServiceInterface.update(ce);
}
} catch (DsConcurrentModificationException e) {
LOG.debug("Equipment reference changed, update instance and retry.", e.getMessage());
ce = equipmentServiceInterface.getByInventoryIdOrNull(apId);
ce.setDetails(apElementConfiguration);
ce = equipmentServiceInterface.update(ce);
}
}
@Override

View File

@@ -0,0 +1,431 @@
package com.telecominfraproject.wlan.opensync.external.integration;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoSession;
import org.mockito.quality.Strictness;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.telecominfraproject.wlan.alarm.AlarmServiceInterface;
import com.telecominfraproject.wlan.client.ClientServiceInterface;
import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails;
import com.telecominfraproject.wlan.client.session.models.ClientSession;
import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails;
import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface;
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
import com.telecominfraproject.wlan.customer.models.Customer;
import com.telecominfraproject.wlan.customer.models.CustomerDetails;
import com.telecominfraproject.wlan.customer.models.EquipmentAutoProvisioningSettings;
import com.telecominfraproject.wlan.customer.service.CustomerServiceInterface;
import com.telecominfraproject.wlan.equipment.EquipmentServiceInterface;
import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration;
import com.telecominfraproject.wlan.equipment.models.Equipment;
import com.telecominfraproject.wlan.firmware.FirmwareServiceInterface;
import com.telecominfraproject.wlan.firmware.models.CustomerFirmwareTrackRecord;
import com.telecominfraproject.wlan.firmware.models.CustomerFirmwareTrackSettings;
import com.telecominfraproject.wlan.location.service.LocationServiceInterface;
import com.telecominfraproject.wlan.opensync.external.integration.controller.OpensyncCloudGatewayController;
import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPVIFState;
import com.telecominfraproject.wlan.profile.ProfileServiceInterface;
import com.telecominfraproject.wlan.profile.models.Profile;
import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration;
import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration;
import com.telecominfraproject.wlan.routing.RoutingServiceInterface;
import com.telecominfraproject.wlan.status.StatusServiceInterface;
import com.telecominfraproject.wlan.status.equipment.models.EquipmentUpgradeStatusData;
import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID;
import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs;
import com.telecominfraproject.wlan.status.models.Status;
import com.telecominfraproject.wlan.status.models.StatusDataType;
import sts.OpensyncStats.Client;
import sts.OpensyncStats.ClientReport;
import sts.OpensyncStats.RadioBandType;
import sts.OpensyncStats.Report;
@RunWith(SpringRunner.class)
@ActiveProfiles(profiles = { "integration_test", })
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = OpensyncExternalIntegrationCloudTest.class)
@Import(value = { AlarmServiceInterface.class, OpensyncExternalIntegrationCloud.class,
OpensyncExternalIntegrationCloudTest.Config.class,
})
public class OpensyncExternalIntegrationCloudTest {
@MockBean(answer = Answers.RETURNS_MOCKS)
AlarmServiceInterface alarmServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
CustomerServiceInterface customerServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
LocationServiceInterface locationServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
OvsdbSessionMapInterface ovsdbSessionMapInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
CloudEventDispatcherInterface equipmentMetricsCollectorInterface;
@MockBean
EquipmentServiceInterface equipmentServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
RoutingServiceInterface routingServiceInterface;
@MockBean
ProfileServiceInterface profileServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
StatusServiceInterface statusServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
ClientServiceInterface clientServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
FirmwareServiceInterface firmwareServiceInterface;
@MockBean(answer = Answers.RETURNS_MOCKS)
OpensyncCloudGatewayController gatewayController;
@Mock(answer = Answers.RETURNS_MOCKS)
ConnectNodeInfo connectNodeInfo;
@Autowired
OpensyncExternalIntegrationCloud opensyncExternalIntegrationCloud;
MockitoSession mockito;
@Configuration
static class Config {
@Bean
public OpensyncExternalIntegrationCloud opensyncExternalIntegrationCloud() {
return new OpensyncExternalIntegrationCloud();
}
@Bean
public CacheManager cacheManager() {
return new CaffeineCacheManager();
}
}
@Before
public void setUp() throws Exception {
mockito = Mockito.mockitoSession().initMocks(this).strictness(Strictness.STRICT_STUBS).startMocking();
}
@After
public void tearDown() throws Exception {
mockito.finishMocking();
}
@Test
public void testGetCustomerEquipment() {
Equipment equipment = new Equipment();
equipment.setDetails(ApElementConfiguration.createWithDefaults());
Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(Mockito.eq("Test_Client_21P10C68818122")))
.thenReturn(equipment);
assertNotNull(opensyncExternalIntegrationCloud.getCustomerEquipment("Test_Client_21P10C68818122"));
assertNull(opensyncExternalIntegrationCloud.getCustomerEquipment("Test_Client_21P10C68818133"));
}
@Test
public void testApConnected() {
connectNodeInfo.wifiRadioStates = ImmutableMap.of("2.4G", "home-ap-24", "5GL", "home-ap-l50", "5GU",
"home-ap-u50");
Customer customer = new Customer();
customer.setId(2);
CustomerDetails customerDetails = new CustomerDetails();
customerDetails.setAutoProvisioning(new EquipmentAutoProvisioningSettings());
customerDetails.getAutoProvisioning().setEnabled(true);
customer.setDetails(new CustomerDetails());
Profile apProfile = new Profile();
apProfile.setDetails(ApNetworkConfiguration.createWithDefaults());
Profile ssidProfile = new Profile();
ssidProfile.setDetails(SsidConfiguration.createWithDefaults());
Mockito.when(profileServiceInterface.create(Mockito.any(Profile.class))).thenReturn(apProfile)
.thenReturn(ssidProfile);
Mockito.when(profileServiceInterface.update(Mockito.any(Profile.class))).thenReturn(apProfile);
Mockito.when(customerServiceInterface.getOrNull(Mockito.anyInt())).thenReturn(customer);
Status fwStatus = new Status();
fwStatus.setDetails(new EquipmentUpgradeStatusData());
Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(),
Mockito.eq(StatusDataType.FIRMWARE))).thenReturn(fwStatus);
Mockito.when(firmwareServiceInterface.getDefaultCustomerTrackSetting())
.thenReturn(new CustomerFirmwareTrackSettings());
CustomerFirmwareTrackRecord fwTrackRecord = new CustomerFirmwareTrackRecord();
fwTrackRecord.setSettings(new CustomerFirmwareTrackSettings());
fwTrackRecord.setTrackRecordId(3);
fwTrackRecord.setCustomerId(2);
Mockito.when(firmwareServiceInterface.getCustomerFirmwareTrackRecord(Mockito.anyInt()))
.thenReturn(fwTrackRecord);
opensyncExternalIntegrationCloud.apConnected("Test_Client_21P10C68818122", connectNodeInfo);
}
@Test
public void testApDisconnected() {
opensyncExternalIntegrationCloud.apDisconnected("Test_Client_21P10C68818122");
}
@Test
public void testGetApConfig() throws Exception {
Equipment equipment = new Equipment();
equipment.setDetails(ApElementConfiguration.createWithDefaults());
Mockito.when(equipmentServiceInterface.getByInventoryIdOrNull(Mockito.any())).thenReturn(equipment);
Profile apProfile = new Profile();
apProfile.setDetails(ApNetworkConfiguration.createWithDefaults());
Profile ssidProfile = new Profile();
ssidProfile.setDetails(SsidConfiguration.createWithDefaults());
List<Profile> profileWithChildren = ImmutableList.of(apProfile, ssidProfile);
Mockito.when(profileServiceInterface.getProfileWithChildren(Mockito.anyLong())).thenReturn(profileWithChildren);
assertNotNull(opensyncExternalIntegrationCloud.getApConfig("Test_Client_21P10C68818122"));
}
@Test
public void testExtractApIdFromTopic() {
String topic = "/ap/Test_Client_21P10C68818122/opensync";
assertEquals("Test_Client_21P10C68818122", OpensyncExternalIntegrationCloud.extractApIdFromTopic(topic));
}
@Test
public void testExtractCustomerIdFromTopic() {
String topic = "/ap/Test_Client_21P10C68818122/opensync";
OvsdbSession session = Mockito.mock(OvsdbSession.class);
Mockito.when(session.getCustomerId()).thenReturn(2);
Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session);
assertEquals(2, opensyncExternalIntegrationCloud.extractCustomerIdFromTopic(topic));
}
@Test
public void testExtractEquipmentIdFromTopic() {
String topic = "/ap/Test_Client_21P10C68818122/opensync";
OvsdbSession session = Mockito.mock(OvsdbSession.class);
Mockito.when(session.getEquipmentId()).thenReturn(1L);
Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session);
assertEquals(1L, opensyncExternalIntegrationCloud.extractEquipmentIdFromTopic(topic));
}
@Test
public void testProcessMqttMessageStringReport() {
Report report = Report.newBuilder().setNodeID("21P10C68818122")
.addAllClients(getOpensyncStatsClientReportsList()).build();
String topic = "/ap/Test_Client_21P10C68818122/opensync";
OvsdbSession session = Mockito.mock(OvsdbSession.class);
Mockito.when(session.getEquipmentId()).thenReturn(1L);
Mockito.when(session.getCustomerId()).thenReturn(2);
Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session);
Status bssidStatus = new Status();
bssidStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS);
bssidStatus.setCustomerId(2);
ActiveBSSIDs activeBssidsDetails = new ActiveBSSIDs();
activeBssidsDetails.setActiveBSSIDs(getActiveBssidList());
bssidStatus.setDetails(activeBssidsDetails);
Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(),
Mockito.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus);
Mockito.when(statusServiceInterface.update(Mockito.any(Status.class))).thenReturn(bssidStatus);
com.telecominfraproject.wlan.client.models.Client clientInstance = new com.telecominfraproject.wlan.client.models.Client();
clientInstance.setMacAddress(new MacAddress("7C:AB:60:E6:EA:4D"));
clientInstance.setDetails(new ClientInfoDetails());
com.telecominfraproject.wlan.client.models.Client clientInstance2 = new com.telecominfraproject.wlan.client.models.Client();
clientInstance2.setMacAddress(new MacAddress("C0:9A:D0:76:A9:69"));
clientInstance2.setDetails(new ClientInfoDetails());
Mockito.when(clientServiceInterface.getOrNull(Mockito.anyInt(), Mockito.any(MacAddress.class)))
.thenReturn(clientInstance).thenReturn(clientInstance2);
Mockito.when(
clientServiceInterface.update(Mockito.any(com.telecominfraproject.wlan.client.models.Client.class)))
.thenReturn(clientInstance).thenReturn(clientInstance2);
ClientSession clientSession = new ClientSession();
clientSession.setMacAddress(new MacAddress("7C:AB:60:E6:EA:4D"));
clientSession.setDetails(new ClientSessionDetails());
ClientSession clientSession2 = new ClientSession();
clientSession2.setMacAddress(new MacAddress("C0:9A:D0:76:A9:69"));
clientSession2.setDetails(new ClientSessionDetails());
Mockito.when(clientServiceInterface.getSessionOrNull(Mockito.anyInt(), Mockito.anyLong(),
Mockito.any(MacAddress.class))).thenReturn(clientSession).thenReturn(clientSession2);
Mockito.when(clientServiceInterface.updateSession(Mockito.any(ClientSession.class))).thenReturn(clientSession)
.thenReturn(clientSession2);
opensyncExternalIntegrationCloud.processMqttMessage(topic, report);
Mockito.verify(clientServiceInterface, Mockito.times(2)).getOrNull(Mockito.anyInt(),
Mockito.any(MacAddress.class));
Mockito.verify(clientServiceInterface, Mockito.times(2)).getSessionOrNull(Mockito.anyInt(), Mockito.anyLong(),
Mockito.any(MacAddress.class));
Mockito.verify(clientServiceInterface, Mockito.times(2)).updateSession(Mockito.any(ClientSession.class));
Mockito.verify(clientServiceInterface, Mockito.times(2))
.update(Mockito.any(com.telecominfraproject.wlan.client.models.Client.class));
Mockito.verify(statusServiceInterface, Mockito.times(3)).getOrNull(Mockito.anyInt(), Mockito.anyLong(),
Mockito.eq(StatusDataType.ACTIVE_BSSIDS));
}
@Test
public void testGetNegativeSignedIntFromUnsigned() {
int unsignedVal = Long.valueOf(4294967239L).intValue();
int expectedVal = -57; // (unsignedValue << 1) >> 1
assert (expectedVal == opensyncExternalIntegrationCloud.getNegativeSignedIntFromUnsigned(unsignedVal));
}
@Ignore
public void testProcessMqttMessageStringFlowReport() {
// TODO: implement me when support flow reports
}
@Ignore
public void testProcessMqttMessageStringWCStatsReport() {
// TODO: implement me when wcs stats reports supported
}
@Ignore
public void testWifiVIFStateDbTableUpdate() {
// TODO: implement me
}
@Ignore
public void testWifiRadioStatusDbTableUpdate() {
// TODO: implement me
}
@Ignore
public void testWifiInetStateDbTableUpdate() {
// TODO: implement me
}
@Ignore
public void testWifiAssociatedClientsDbTableUpdate() {
// TODO: implement me
}
@Ignore
public void testAwlanNodeDbTableUpdate() {
// TODO: implement me
}
@Test
public void testWifiVIFStateDbTableDelete() {
Status bssidStatus = new Status();
bssidStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS);
bssidStatus.setCustomerId(2);
ActiveBSSIDs activeBssidsDetails = new ActiveBSSIDs();
activeBssidsDetails.setActiveBSSIDs(getActiveBssidList());
bssidStatus.setDetails(activeBssidsDetails);
Mockito.when(statusServiceInterface.getOrNull(Mockito.anyInt(), Mockito.anyLong(),
Mockito.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus);
opensyncExternalIntegrationCloud.wifiVIFStateDbTableDelete(ImmutableList.of(new OpensyncAPVIFState()), "apId");
}
@Test
public void testWifiAssociatedClientsDbTableDelete() {
opensyncExternalIntegrationCloud.wifiAssociatedClientsDbTableDelete("7C:AB:60:E6:EA:4D", "apId");
}
// Helper methods
private List<ActiveBSSID> getActiveBssidList() {
ActiveBSSID activeBssid = new ActiveBSSID();
activeBssid.setBssid("24:f5:a2:ef:2e:54");
activeBssid.setSsid("ssid-1");
activeBssid.setNumDevicesConnected(1);
activeBssid.setRadioType(RadioType.is2dot4GHz);
ActiveBSSID activeBssid2 = new ActiveBSSID();
activeBssid2.setBssid("24:f5:a2:ef:2e:55");
activeBssid2.setSsid("ssid-2");
activeBssid2.setNumDevicesConnected(0);
activeBssid2.setRadioType(RadioType.is5GHzL);
ActiveBSSID activeBssid3 = new ActiveBSSID();
activeBssid3.setBssid("24:f5:a2:ef:2e:56");
activeBssid3.setSsid("ssid-3");
activeBssid3.setNumDevicesConnected(1);
activeBssid3.setRadioType(RadioType.is5GHzU);
List<ActiveBSSID> bssidList = new ArrayList<ActiveBSSID>();
bssidList.add(activeBssid);
bssidList.add(activeBssid2);
bssidList.add(activeBssid3);
return bssidList;
}
private List<ClientReport> getOpensyncStatsClientReportsList() {
int rssi = Long.valueOf(4294967239L).intValue();
Client.Stats clientStats = Client.Stats.getDefaultInstance().toBuilder().setRssi(rssi).setRxBytes(225554786)
.setRxRate(24000.0).setTxBytes(1208133026).setTxRate(433300.0).build();
Client client2g = Client.getDefaultInstance().toBuilder().setMacAddress("7C:AB:60:E6:EA:4D").setSsid("ssid-1")
.setConnected(true).setDurationMs(59977).setStats(clientStats).build();
Client client5gu = Client.getDefaultInstance().toBuilder().setMacAddress("C0:9A:D0:76:A9:69").setSsid("ssid-3")
.setConnected(true).setDurationMs(298127).setStats(clientStats).build();
ClientReport clientReport2g = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND2G)
.setChannel(6).addAllClientList(ImmutableList.of(client2g)).build();
ClientReport clientReport5gl = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND5GL)
.setChannel(36).build();
ClientReport clientReport5gu = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND5GU)
.setChannel(157).addAllClientList(ImmutableList.of(client5gu)).build();
List<ClientReport> clients = new ArrayList<ClientReport>();
clients.add(clientReport2g);
clients.add(clientReport5gl);
clients.add(clientReport5gu);
return clients;
}
}