bf678ffed451f4c99214076b2cdce93d0bd6c89b
[controller.git] / opendaylight / config / config-manager-facade-xml / src / test / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / fromxml / SimpleIdentityRefAttributeReadingStrategyTest.java
1 /*
2  * Copyright (c) 2015, 2017 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.config.facade.xml.mapping.attributes.fromxml;
10
11 import static org.junit.Assert.assertEquals;
12
13 import com.google.common.collect.Maps;
14 import java.net.URI;
15 import java.util.Collections;
16 import java.util.Date;
17 import java.util.Map;
18 import org.junit.Test;
19 import org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping;
20 import org.opendaylight.controller.config.util.xml.XmlElement;
21
22 public class SimpleIdentityRefAttributeReadingStrategyTest {
23
24     @Test
25     public void testReadIdRef() throws Exception {
26         final Map<String, Map<Date, IdentityMapping>> identityMapping = Maps.newHashMap();
27         final IdentityMapping value = new IdentityMapping();
28         final Date rev = new Date();
29         identityMapping.put("namespace", Collections.singletonMap(rev, value));
30         identityMapping.put("inner", Collections.singletonMap(rev, value));
31         final SimpleIdentityRefAttributeReadingStrategy key = new SimpleIdentityRefAttributeReadingStrategy(null, "key",
32                 identityMapping);
33
34         String read = key.readElementContent(XmlElement.fromString("<el xmlns=\"namespace\">local</el>"));
35         assertEquals(
36                 org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(),
37                 read);
38
39         read = key.readElementContent(XmlElement.fromString("<el xmlns:a=\"inner\" xmlns=\"namespace\">a:local</el>"));
40         assertEquals(org.opendaylight.yangtools.yang.common.QName.create(URI.create("inner"), rev, "local").toString(),
41                 read);
42
43         read = key.readElementContent(
44                 XmlElement.fromString("<top xmlns=\"namespace\"><el>local</el></top>").getOnlyChildElement());
45         assertEquals(
46                 org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(),
47                 read);
48     }
49 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.