blob: 1a87ace71263f19ec4531d4531c081bd7ac8e863 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2014, 2017 Orange.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.om2m.datamapping.jaxb;
import static org.junit.Assert.*;
import org.eclipse.om2m.commons.constants.MimeMediaType;
import org.eclipse.om2m.commons.resource.flexcontainerspec.BinarySwitchFlexContainer;
import org.eclipse.om2m.commons.resource.flexcontainerspec.DeviceLightFlexContainer;
import org.eclipse.om2m.commons.resource.flexcontainerspec.ToggleFlexContainer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class MapperTestDeviceLightFlexContainer extends AbstractMapperTest {
private Mapper jsonMapper;
private Mapper xmlMapper;
@Before
public void setUp() throws Exception {
jsonMapper = new Mapper(MimeMediaType.JSON);
xmlMapper = new Mapper(MimeMediaType.XML);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testStringToObj_json() {
String xmlPayload = readFile("src/test/resources/deviceLightFlexContainer.json");
DeviceLightFlexContainer deviceLightFlexContainer = (DeviceLightFlexContainer) jsonMapper.stringToObj(xmlPayload);
assertNotNull(deviceLightFlexContainer);
assertFalse(deviceLightFlexContainer.getFlexContainerOrContainerOrSubscription().isEmpty());
assertTrue(deviceLightFlexContainer.getFlexContainerOrContainerOrSubscription().size() == 1);
Object binarySwitchObject = deviceLightFlexContainer.getFlexContainerOrContainerOrSubscription().get(0);
assertTrue(binarySwitchObject instanceof BinarySwitchFlexContainer);
BinarySwitchFlexContainer binarySwitchFlexContainer = (BinarySwitchFlexContainer) binarySwitchObject;
assertNotNull(binarySwitchFlexContainer.getToggle());
assertNotNull(binarySwitchFlexContainer.getFlexContainerOrContainerOrSubscription());
assertFalse(binarySwitchFlexContainer.getFlexContainerOrContainerOrSubscription().isEmpty());
assertTrue(binarySwitchFlexContainer.getFlexContainerOrContainerOrSubscription().size() == 1);
Object toggleObject = binarySwitchFlexContainer.getFlexContainerOrContainerOrSubscription().get(0);
assertTrue(toggleObject instanceof ToggleFlexContainer);
}
}