|
| 1 | +/* |
| 2 | + * Copyright 2014 Deutsche Nationalbibliothek |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 the "License"; |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.culturegraph.mf.stream.converter.xml; |
| 17 | + |
| 18 | +import static org.mockito.Mockito.verify; |
| 19 | + |
| 20 | +import org.culturegraph.mf.framework.StreamReceiver; |
| 21 | +import org.junit.After; |
| 22 | +import org.junit.Before; |
| 23 | +import org.junit.Test; |
| 24 | +import org.mockito.Mock; |
| 25 | +import org.mockito.MockitoAnnotations; |
| 26 | +import org.xml.sax.SAXException; |
| 27 | +import org.xml.sax.helpers.AttributesImpl; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author Christoph Böhme |
| 31 | + * |
| 32 | + */ |
| 33 | +public final class MarcXmlHandlerTest { |
| 34 | + |
| 35 | + private static final String CONTROLFIELD = "controlfield"; |
| 36 | + private static final String NAMESPACE = "http://www.loc.gov/MARC21/slim"; |
| 37 | + |
| 38 | + private MarcXmlHandler marcXmlHandler; |
| 39 | + |
| 40 | + @Mock |
| 41 | + private StreamReceiver receiver; |
| 42 | + |
| 43 | + @Before |
| 44 | + public void setup() { |
| 45 | + MockitoAnnotations.initMocks(this); |
| 46 | + marcXmlHandler = new MarcXmlHandler(); |
| 47 | + marcXmlHandler.setReceiver(receiver); |
| 48 | + } |
| 49 | + |
| 50 | + @After |
| 51 | + public void cleanup() { |
| 52 | + marcXmlHandler.closeStream(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void shouldFindTagAttributeAtSecondPositionInControlFieldElement() |
| 57 | + throws SAXException { |
| 58 | + final AttributesImpl attributes = new AttributesImpl(); |
| 59 | + attributes.addAttribute(NAMESPACE, "id", "id", "CDATA", "id-1"); |
| 60 | + attributes.addAttribute(NAMESPACE, "tag", "tag", "CDATA", "001"); |
| 61 | + |
| 62 | + final String fieldValue = "1234"; |
| 63 | + |
| 64 | + marcXmlHandler.startElement(NAMESPACE, CONTROLFIELD, "", attributes); |
| 65 | + marcXmlHandler.characters(fieldValue.toCharArray(), 0, fieldValue.length()); |
| 66 | + marcXmlHandler.endElement(NAMESPACE, CONTROLFIELD, ""); |
| 67 | + |
| 68 | + verify(receiver).literal("001", fieldValue); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments