2 * Copyright © 2016 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.test;
10 import com.google.common.base.Preconditions;
11 import com.google.common.base.Strings;
12 import java.io.InputStream;
13 import java.util.Collections;
14 import java.util.HashMap;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Base class for device tests, should be used, when device databroker is needed
26 public abstract class AbstractDeviceTest {
28 private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceTest.class);
29 private final Map<String, DeviceWrapper> internalStorage;
32 * Default constructor only initializes the inner
33 * {@link AbstractDeviceTest#internalStorage} as asynchronized {@link Map}.
35 public AbstractDeviceTest() {
36 this.internalStorage = Collections.synchronizedMap(new HashMap<>());
40 * Insert a created device into {@link AbstractDeviceTest#internalStorage}.
42 * @see DeviceWrapper#createDeviceWrapper(String, InputStream, QName)
43 * @param key identifier of device simulator (wrapper)
44 * @param initialDataXmlInputStream {@link InputStream} of xml with initial simulator data
45 * @param intialDataQName {@link QName} of initial simulator data
46 * @return device simulator (wrapper)
48 public DeviceWrapper createDeviceWrapper(@Nonnull String key, @Nonnull InputStream initialDataXmlInputStream,
49 @Nonnull QName intialDataQName) {
50 DeviceWrapper deviceWrapper =
51 DeviceWrapper.createDeviceWrapper(key, initialDataXmlInputStream, intialDataQName);
52 LOG.info("Creating a new device wrapper {}, {}", key, deviceWrapper);
53 internalStorage.put(key, deviceWrapper);
58 * Returns the {@link DeviceWrapper} identified by the key provided as param.
60 * @param deviceIdentifier identifier of device simulator
61 * @return stored device or null if not found
63 public DeviceWrapper getDevice(@Nonnull String deviceIdentifier) {
64 Preconditions.checkArgument(!Strings.isNullOrEmpty(deviceIdentifier));
65 return internalStorage.get(deviceIdentifier);