xsql should pull junit directly
[controller.git] / opendaylight / netconf / netconf-testtool / src / main / java / org / opendaylight / controller / netconf / test / tool / FakeModuleBuilderCapability.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.test.tool;
10
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.confignetconfconnector.util.Util;
16 import org.opendaylight.controller.netconf.mapping.api.Capability;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
19
20 /**
21  * Can be passed instead of ModuleBuilderCapability when building capabilities
22  * in NetconfDeviceSimulator when testing various schema resolution related exceptions.
23  */
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;
28
29     public FakeModuleBuilderCapability(final ModuleBuilder input, final String inputStream) {
30         this.input = input;
31         this.content = Optional.of(inputStream);
32     }
33
34     @Override
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;
39     }
40
41     @Override
42     public Optional<String> getModuleNamespace() {
43         return Optional.of(input.getNamespace().toString());
44     }
45
46     @Override
47     public Optional<String> getModuleName() {
48         return Optional.of(input.getName());
49     }
50
51     @Override
52     public Optional<String> getRevision() {
53         return Optional.of(hasRevision() ? QName.formattedRevision(input.getRevision()) : "");
54     }
55
56     private boolean hasRevision() {
57         return !input.getRevision().equals(NO_REVISION);
58     }
59
60     /**
61      *
62      * @return empty schema source to trigger schema resolution exception.
63      */
64     @Override
65     public Optional<String> getCapabilitySchema() {
66         return Optional.absent();
67     }
68
69     @Override
70     public List<String> getLocation() {
71         return Collections.emptyList();
72     }
73 }