2 * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.netconf.test.tool;
11 import com.google.common.base.Optional;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
15 import org.opendaylight.controller.netconf.api.Capability;
16 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
21 * Can be passed instead of ModuleBuilderCapability when building capabilities
22 * in NetconfDeviceSimulator when testing various schema resolution related exceptions.
24 public class FakeModuleBuilderCapability implements Capability{
25 private static final Date NO_REVISION = new Date(0);
26 private final ModuleBuilder input;
27 private final Optional<String> content;
29 public FakeModuleBuilderCapability(final ModuleBuilder input, final String inputStream) {
31 this.content = Optional.of(inputStream);
35 public String getCapabilityUri() {
36 // FIXME capabilities in Netconf-impl need to check for NO REVISION
37 final String withoutRevision = getModuleNamespace().get() + "?module=" + getModuleName().get();
38 return hasRevision() ? withoutRevision + "&revision=" + Util.writeDate(input.getRevision()) : withoutRevision;
42 public Optional<String> getModuleNamespace() {
43 return Optional.of(input.getNamespace().toString());
47 public Optional<String> getModuleName() {
48 return Optional.of(input.getName());
52 public Optional<String> getRevision() {
53 return Optional.of(hasRevision() ? QName.formattedRevision(input.getRevision()) : "");
56 private boolean hasRevision() {
57 return !input.getRevision().equals(NO_REVISION);
62 * @return empty schema source to trigger schema resolution exception.
65 public Optional<String> getCapabilitySchema() {
66 return Optional.absent();
70 public List<String> getLocation() {
71 return Collections.emptyList();