Search in sources :

Example 1 with XmlReader

use of org.ovirt.api.metamodel.runtime.xml.XmlReader in project ovirt-engine-sdk-java by oVirt.

the class ActionReaderTest method testFaultActionWithReason.

/**
 * Checks that having fault action with reason and detail is handled correctly
 */
@Test
public void testFaultActionWithReason() throws Exception {
    String response = "<action><fault><reason>myreason</reason><detail>mydetail</detail></fault></action>";
    try (InputStream stream = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8));
        XmlReader reader = new XmlReader(stream)) {
        Action action = XmlActionReader.readOne(reader);
        assertTrue(action.faultPresent());
        assertTrue(action.fault().reasonPresent());
        assertEquals("myreason", action.fault().reason());
        assertTrue(action.fault().detailPresent());
        assertEquals("mydetail", action.fault().detail());
    }
}
Also used : Action(org.ovirt.engine.sdk4.types.Action) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlReader(org.ovirt.api.metamodel.runtime.xml.XmlReader) Test(org.junit.Test)

Example 2 with XmlReader

use of org.ovirt.api.metamodel.runtime.xml.XmlReader in project ovirt-engine-sdk-java by oVirt.

the class ActionReaderTest method testFaultActionNoValue.

/**
 * Checks that having fault action empty is handled correctly
 */
@Test
public void testFaultActionNoValue() throws Exception {
    try (InputStream stream = new ByteArrayInputStream("<fault/>".getBytes(StandardCharsets.UTF_8));
        XmlReader reader = new XmlReader(stream)) {
        Action action = XmlActionReader.readOne(reader);
        assertFalse(action.statusPresent());
        assertFalse(action.faultPresent());
        assertNull(action.fault());
        assertNull(action.status());
    }
}
Also used : Action(org.ovirt.engine.sdk4.types.Action) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlReader(org.ovirt.api.metamodel.runtime.xml.XmlReader) Test(org.junit.Test)

Example 3 with XmlReader

use of org.ovirt.api.metamodel.runtime.xml.XmlReader in project ovirt-engine-sdk-java by oVirt.

the class ActionReaderTest method testFaultAndStatusActionW.

/**
 * Checks that having fault and status action is handled correctly
 */
@Test
public void testFaultAndStatusActionW() throws Exception {
    String response = "<action><status>mystatus</status><fault><reason>myreason</reason></fault></action>";
    try (InputStream stream = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8));
        XmlReader reader = new XmlReader(stream)) {
        Action action = XmlActionReader.readOne(reader);
        // Check state:
        assertTrue(action.statusPresent());
        assertEquals("mystatus", action.status());
        // Check reason:
        assertTrue(action.faultPresent());
        assertTrue(action.fault().reasonPresent());
        assertEquals("myreason", action.fault().reason());
    }
}
Also used : Action(org.ovirt.engine.sdk4.types.Action) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlReader(org.ovirt.api.metamodel.runtime.xml.XmlReader) Test(org.junit.Test)

Example 4 with XmlReader

use of org.ovirt.api.metamodel.runtime.xml.XmlReader in project ovirt-engine-sdk-java by oVirt.

the class ActionReaderTest method testActionWithState.

/**
 * Checks that having action with state is handled correctly
 */
@Test
public void testActionWithState() throws Exception {
    String response = "<action><status>mystatus</status></action>";
    try (InputStream stream = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8));
        XmlReader reader = new XmlReader(stream)) {
        Action action = XmlActionReader.readOne(reader);
        assertTrue(action.statusPresent());
        assertEquals("mystatus", action.status());
    }
}
Also used : Action(org.ovirt.engine.sdk4.types.Action) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlReader(org.ovirt.api.metamodel.runtime.xml.XmlReader) Test(org.junit.Test)

Example 5 with XmlReader

use of org.ovirt.api.metamodel.runtime.xml.XmlReader in project ovirt-engine-sdk-java by oVirt.

the class ClusterReaderTest method testReadValueAfterEmptyList.

/**
 * Test given switch type after empty RNG source both are read correctly.
 */
@Test
public void testReadValueAfterEmptyList() throws Exception {
    String response = "<cluster>" + "<required_rng_sources/>" + "<switch_type>legacy</switch_type>" + "</cluster>";
    try (InputStream stream = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8));
        XmlReader reader = new XmlReader(stream)) {
        Cluster cluster = XmlClusterReader.readOne(reader);
        assertEquals(Arrays.asList(), cluster.requiredRngSources());
        assertEquals(SwitchType.LEGACY, cluster.switchType());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Cluster(org.ovirt.engine.sdk4.types.Cluster) XmlReader(org.ovirt.api.metamodel.runtime.xml.XmlReader) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 XmlReader (org.ovirt.api.metamodel.runtime.xml.XmlReader)5 Action (org.ovirt.engine.sdk4.types.Action)4 Cluster (org.ovirt.engine.sdk4.types.Cluster)1