summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/command/PpsMoDataTest.java
blob: e4f2a15210622a14730ebc3d810b3a0cfe8f1cfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wifi.hotspot2.soap.command;

import static com.android.server.wifi.hotspot2.soap.command.PpsMoData.ADD_MO_COMMAND;
import static com.android.server.wifi.hotspot2.soap.command.PpsMoData.ATTRIBUTE_MANAGEMENT_TREE_URI;
import static com.android.server.wifi.hotspot2.soap.command.PpsMoData.ATTRIBUTE_MO_URN;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.MockitoAnnotations.initMocks;

import android.support.test.filters.SmallTest;

import org.junit.Before;
import org.junit.Test;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapPrimitive;

/**
 * Unit tests for {@link PpsMoData}.
 */
@SmallTest
public class PpsMoDataTest {
    private static final String TEST_PPS_MO_XML = "<MgmtTree>test</MgmtTree>";
    private static final String TEST_TREE_URI = "testTreeURI";
    private static final String TEST_MO_URN = "testMoURN";

    /**
     * Sets up test.
     */
    @Before
    public void setUp() throws Exception {
        initMocks(this);
    }

    /**
     * Verify if a message is valid format, it will return a PPS MO XML.
     */
    @Test
    public void verifyGetPpsMo() {
        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName(ADD_MO_COMMAND);
        SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML);
        soapPrimitive.addAttribute(ATTRIBUTE_MANAGEMENT_TREE_URI, TEST_TREE_URI);
        soapPrimitive.addAttribute(ATTRIBUTE_MO_URN, TEST_MO_URN);
        propertyInfo.setValue(soapPrimitive);

        assertEquals(TEST_PPS_MO_XML, PpsMoData.createInstance(propertyInfo).getPpsMoTree());
    }

    /**
     * Verify if a message does not have PPS MO XML, it will return {@code null}.
     */
    @Test
    public void verifyMissingPpsMoReturnNull() {
        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName(ADD_MO_COMMAND);
        SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML);
        soapPrimitive.addAttribute(ATTRIBUTE_MANAGEMENT_TREE_URI, TEST_TREE_URI);
        soapPrimitive.addAttribute(ATTRIBUTE_MO_URN, TEST_MO_URN);
        propertyInfo.setValue(null);

        assertNull(PpsMoData.createInstance(propertyInfo));
    }

    /**
     * Verify if a message is missing {@link PpsMoData#ATTRIBUTE_MANAGEMENT_TREE_URI}, it will
     * return {@code null}.
     */
    @Test
    public void verifyMissingTreeURIAttributeReturnNull() {
        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName(ADD_MO_COMMAND);
        SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML);
        soapPrimitive.addAttribute(ATTRIBUTE_MO_URN, TEST_MO_URN);
        propertyInfo.setValue(soapPrimitive);

        assertNull(PpsMoData.createInstance(propertyInfo));
    }

    /**
     * Verify if a message is missing {@link PpsMoData#ATTRIBUTE_MO_URN}, it will return
     * {@code null}.
     */
    @Test
    public void verifyMissingMoUrnAttributeReturnNull() {
        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName(ADD_MO_COMMAND);
        SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML);
        soapPrimitive.addAttribute(ATTRIBUTE_MANAGEMENT_TREE_URI, TEST_TREE_URI);
        propertyInfo.setValue(soapPrimitive);

        assertNull(PpsMoData.createInstance(propertyInfo));
    }

    /**
     * Verify if a message that is not for addMO command, it will return {@code null}.
     */
    @Test
    public void verifyNonAddMoCommandMessageReturnNull() {
        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName("InvalidCommand");

        assertNull(PpsMoData.createInstance(propertyInfo));
    }
}