use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.
the class QueryObjTest method mandatoryKeyForClassWithoutTargetShouldThrowError.
@Test
void mandatoryKeyForClassWithoutTargetShouldThrowError() throws DynConfigException {
QueryKey<String> mode = new QueryKey<>("mode", "GET", true);
mode.setVerifier(s -> s.equalsIgnoreCase("GET") || s.equalsIgnoreCase("POST"));
URI uri = URI.create("opc.tcp://host:500/path?mode=GET");
QueryObj queryObj = new QueryObj(uri, Collections.singletonList(mode));
DataTag.CreateBuilder builder = DataTag.create("a", Object.class, new DataTagAddress(new HardwareAddressImpl()));
assertThrows(DynConfigException.class, () -> queryObj.applyQueryPropertiesTo(builder));
}
use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.
the class QueryObjTest method createQueryObjWithMissingKeyShouldThrowException.
@Test
void createQueryObjWithMissingKeyShouldThrowException() {
List<QueryKey<?>> key = Collections.singletonList(new QueryKey<Integer>("missing", null, true));
assertThrows(DynConfigException.class, () -> new QueryObj(uri, key));
}
use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.
the class QueryObjTest method mandatoryKeyForClassWithTargetShouldPassWork.
@Test
void mandatoryKeyForClassWithTargetShouldPassWork() throws DynConfigException {
QueryKey<String> mode = new QueryKey<>("mode", "GET", true);
mode.setVerifier(s -> s.equalsIgnoreCase("GET") || s.equalsIgnoreCase("POST"));
mode.setTargetClass(DataTagAddress.class);
URI uri = URI.create("opc.tcp://host:500/path?mode=GET");
QueryObj queryObj = new QueryObj(uri, Collections.singletonList(mode));
DataTag.CreateBuilder builder = DataTag.create("a", Object.class, new DataTagAddress(new HardwareAddressImpl()));
queryObj.applyQueryPropertiesTo(builder);
}
use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.
the class RestConfigStrategy method prepareDataTagConfigurations.
/**
* Create appropriate preliminary data tag configurations with a @{@link cern.c2mon.shared.common.datatag.address.DIPHardwareAddress}
* which can then be passed to the C2MON server for creation.
* @return the preliminary DataTags to pass on to the C2MON server for creation.
* @throws DynConfigException if a value in the query cannot be converted to the necessary class, but is mandatory.
*/
public DataTag prepareDataTagConfigurations() throws DynConfigException {
HardwareAddress restHardwareAddress = new HardwareAddressImpl();
DataTag dataTag = super.toTagConfiguration(restHardwareAddress);
HashMap<String, String> params = keys.stream().filter(k -> queryObj.contains(k)).collect(Collectors.toMap(QueryKey::getKeyName, o -> StringUtils.join(queryObj.get(o, String.class), ", "), (o, o2) -> o, HashMap::new));
dataTag.getAddress().setAddressParameters(params);
return dataTag;
}
use of cern.c2mon.client.core.configuration.dynamic.query.QueryKey in project c2mon by c2mon.
the class QueryObjTest method createQueryObjWithValidKeyShouldHaveNoInfluence.
@Test
void createQueryObjWithValidKeyShouldHaveNoInfluence() throws DynConfigException {
QueryObj expected = new QueryObj(uri, Collections.emptyList());
List<QueryKey<?>> key = Collections.singletonList(new QueryKey<Integer>("tagName", null, true));
queryObj = new QueryObj(uri, key);
assertEquals(expected, queryObj);
}
Aggregations