forked from community/device-mgt-core
revert-70aa11f8
parent
7feb390cef
commit
a31767d114
@ -0,0 +1,95 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import javax.xml.XMLConstants;
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import javax.xml.validation.Schema;
|
||||||
|
import javax.xml.validation.SchemaFactory;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class DeviceManagementConfigTests {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceManagementConfigTests.class);
|
||||||
|
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY =
|
||||||
|
"./src/test/resources/config/malformed-cdm-config-no-mgt-repo.xml";
|
||||||
|
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG =
|
||||||
|
"./src/test/resources/config/malformed-cdm-config-no-ds-config.xml";
|
||||||
|
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG =
|
||||||
|
"./src/test/resources/config/malformed-cdm-config-no-jndi-config.xml";
|
||||||
|
private static final String TEST_CONFIG_SCHEMA_LOCATION =
|
||||||
|
"./src/test/resources/config/schema/DeviceManagementConfigSchema.xsd";
|
||||||
|
|
||||||
|
private Schema schema;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
private void initSchema() {
|
||||||
|
File deviceManagementSchemaConfig = new File(DeviceManagementConfigTests.TEST_CONFIG_SCHEMA_LOCATION);
|
||||||
|
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||||
|
try {
|
||||||
|
schema = sf.newSchema(deviceManagementSchemaConfig);
|
||||||
|
} catch (SAXException e) {
|
||||||
|
Assert.fail("Invalid schema found", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test()
|
||||||
|
public void testMandateManagementRepositoryElement() {
|
||||||
|
File malformedConfig =
|
||||||
|
new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
||||||
|
this.validateConfig(malformedConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMandateDataSourceConfigurationElement() {
|
||||||
|
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
||||||
|
this.validateConfig(malformedConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMandateJndiLookupDefinitionElement() {
|
||||||
|
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
||||||
|
this.validateConfig(malformedConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateConfig(File malformedConfig) {
|
||||||
|
try {
|
||||||
|
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
|
||||||
|
Unmarshaller um = ctx.createUnmarshaller();
|
||||||
|
um.setSchema(this.getSchema());
|
||||||
|
um.unmarshal(malformedConfig);
|
||||||
|
Assert.assertTrue(false);
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Schema getSchema() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||||
|
|
||||||
|
public class DeviceManagementRepositoryTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddDeviceManagementService() {
|
||||||
|
DeviceManagerService sourceProvider = new TestDeviceManagerService();
|
||||||
|
DeviceManagementRepository repository = new DeviceManagementRepository();
|
||||||
|
repository.addDeviceManagementProvider(sourceProvider);
|
||||||
|
|
||||||
|
DeviceManagerService targetProvider =
|
||||||
|
repository.getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
|
||||||
|
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.OperationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TestDeviceManagerService implements DeviceManagerService {
|
||||||
|
|
||||||
|
public static final String DEVICE_TYPE_TEST = "Test";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProviderType() {
|
||||||
|
return TestDeviceManagerService.DEVICE_TYPE_TEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OperationManager getOperationManager() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
public class TestUtils {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(TestUtils.class);
|
||||||
|
|
||||||
|
public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) {
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.warn("Error occurred while closing result set", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stmt != null) {
|
||||||
|
try {
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.warn("Error occurred while closing prepared statement", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (conn != null) {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.warn("Error occurred while closing database connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~ WSO2 Inc. 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.
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<DeviceMgtConfiguration>
|
||||||
|
<ManagementRepository>
|
||||||
|
<MalformedDataSourceConfiguration>
|
||||||
|
<JndiLookupDefinition>
|
||||||
|
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||||
|
</JndiLookupDefinition>
|
||||||
|
</MalformedDataSourceConfiguration>
|
||||||
|
</ManagementRepository>
|
||||||
|
</DeviceMgtConfiguration>
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~ WSO2 Inc. 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.
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<DeviceMgtConfiguration>
|
||||||
|
<ManagementRepository>
|
||||||
|
<DataSourceConfiguration>
|
||||||
|
<MalformedJndiLookupDefinition>
|
||||||
|
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||||
|
</MalformedJndiLookupDefinition>
|
||||||
|
</DataSourceConfiguration>
|
||||||
|
</ManagementRepository>
|
||||||
|
</DeviceMgtConfiguration>
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~ WSO2 Inc. 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.
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<DeviceMgtConfiguration>
|
||||||
|
<MalformedManagementRepository>
|
||||||
|
<DataSourceConfiguration>
|
||||||
|
<JndiLookupDefinition>
|
||||||
|
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||||
|
</JndiLookupDefinition>
|
||||||
|
</DataSourceConfiguration>
|
||||||
|
</MalformedManagementRepository>
|
||||||
|
</DeviceMgtConfiguration>
|
||||||
|
|
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||||
|
attributeFormDefault="unqualified">
|
||||||
|
<xs:element name="DeviceMgtConfiguration">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="ManagementRepository" minOccurs="1" maxOccurs="1" type="DataSourceConfigurationType"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:complexType name="JndiLookupDefinitionType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
|
||||||
|
<xs:complexType name="DataSourceConfigurationType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="JndiLookupDefinition" minOccurs="1" maxOccurs="1"
|
||||||
|
type="JndiLookupDefinitionType"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
|
||||||
|
<xs:complexType name="ManagementRepositoryType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="DataSourceConfiguration" minOccurs="1" maxOccurs="1"
|
||||||
|
type="DataSourceConfigurationType"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:schema>
|
Loading…
Reference in new issue