BUG-6858: adapt to ise api, wire harvestAll to template-provider
[groupbasedpolicy.git] / sxp-integration / sxp-ise-adapter / src / test / java / org / opendaylight / groupbasedpolicy / sxp_ise_adapter / impl / util / IseReplyUtilTest.java
1 /*
2  * Copyright (c) 2016 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.groupbasedpolicy.sxp_ise_adapter.impl.util;
10
11 import static org.opendaylight.groupbasedpolicy.sxp_ise_adapter.impl.IseResourceTestHelper.readLocalResource;
12
13 import com.google.common.collect.Iterables;
14 import java.io.IOException;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.Map;
18 import javax.xml.xpath.XPath;
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.runners.MockitoJUnitRunner;
24 import org.w3c.dom.Node;
25 import org.w3c.dom.NodeList;
26 import org.xml.sax.InputSource;
27
28 /**
29  * Test for {@link IseReplyUtil}.
30  */
31 @RunWith(MockitoJUnitRunner.class)
32 public class IseReplyUtilTest {
33
34     private final String iseReplyAllSgts;
35     private XPath xpath;
36
37     public IseReplyUtilTest() throws IOException {
38         iseReplyAllSgts = readLocalResource("./rawIse-allSgts2.xml");
39     }
40
41     @Before
42     public void setUp() throws Exception {
43         xpath = IseReplyUtil.setupXpath();
44     }
45
46     @Test
47     public void filterNewResourcesByID() throws Exception {
48         final Map<String, Integer> uuidMap = new HashMap<>();
49         uuidMap.put("abc123", 42);
50
51         final InputSource inputSource = IseReplyUtil.createInputSource(iseReplyAllSgts);
52         final NodeList allSgtResourceNodes = IseReplyUtil.findAllSgtResourceNodes(xpath, inputSource);
53
54         final Collection<Node> filteredNodes = IseReplyUtil.filterNewResourcesByID(uuidMap, xpath, allSgtResourceNodes);
55
56         Assert.assertEquals(1, filteredNodes.size());
57         Assert.assertEquals("https://example.org:9060/ers/config/sgt/abc124", Iterables.getFirst(filteredNodes, null).getNodeValue());
58     }
59 }