YoutrackUnmarshallerTest.java
3.05 KB
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
package pl.itcrowd.youtrack.api.rest;
import org.junit.Test;
import pl.itcrowd.youtrack.api.YoutrackUnmarshaller;
import pl.itcrowd.youtrack.api.exceptions.YoutrackAPIException;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import static junit.framework.Assert.assertEquals;
public class YoutrackUnmarshallerTest {
@Test
public void unmarshalEmptyError() throws JAXBException, IOException
{
// Given
final String extendedErrorResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><error></error>";
// When
final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse);
// THen
assertEquals("", errorText);
}
@Test
public void unmarshalError() throws JAXBException, IOException
{
// Given
final String extendedErrorResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><error>Estimated completion time</error>";
// When
final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse);
// THen
assertEquals("Estimated completion time", errorText);
}
@Test
public void unmarshalExtendedError() throws JAXBException, IOException
{
// Given
final String extendedErrorResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><error><message>Estimate task before starting work on it</message><field>Estimated completion time</field></error>";
// When
final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse);
// Then
assertEquals("Estimate task before starting work on it", errorText);
}
@Test
public void unmarshalExtendedErrorWithMessageOnly() throws JAXBException, IOException
{
// Given
final String extendedErrorResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><error><message>Estimate task before starting work on it</message></error>";
// When
final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse);
// Then
assertEquals("Estimate task before starting work on it", errorText);
}
@Test
public void unmarshalExtendedErrorWithEmptyMessage() throws JAXBException, IOException
{
// Given
final String extendedErrorResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><error><message></message><field>Estimated completion time</field></error>";
// When
final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse);
// Then
assertEquals("", errorText);
}
@Test(expected = YoutrackAPIException.class)
public void unmarshalExtendedErrorWithoutMessage() throws JAXBException, IOException
{
// Given
final String extendedErrorResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><error><field>Estimated completion time</field></error>";
// When
YoutrackUnmarshaller.unmarshalError(extendedErrorResponse);
}
}