/*
 * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.data.codec.gson;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;

import com.google.gson.stream.JsonReader;
import java.io.StringReader;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;

public class YT1411Test extends AbstractComplexJsonTest {
    @Test
    public void testChoiceCaseChoiceIdentifier() {
        final var result = new NormalizedNodeResult();
        final var streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
        final var jsonParser = JsonParserStream.create(streamWriter,
            JSONCodecFactorySupplier.RFC7951.getShared(schemaContext));
        jsonParser.parse(new JsonReader(new StringReader("{\n"
            + "  \"complexjson:cont1\": {\n"
            + "    \"lst11\": [\n"
            + "      {\n"
            + "        \"key111\": \"foo\",\n"
            + "        \"lf111\": \"bar\",\n"
            + "        \"lf112\": \"/complexjson:cont1/case11-choice-case-container\"\n"
            + "      }\n"
            + "    ]\n"
            + "  }\n"
            + "}")));
        final var cont1 = result.getResult();
        assertThat(cont1, instanceOf(ContainerNode.class));

        final QName lst11 = QName.create(CONT_1, "lst11");
        final var lf112 = NormalizedNodes.findNode(cont1,
            new NodeIdentifier(lst11),
            NodeIdentifierWithPredicates.of(lst11,
                Map.of(QName.create(CONT_1, "key111"), "foo", QName.create(CONT_1, "lf111"), "bar")),
            new NodeIdentifier(QName.create(CONT_1, "lf112")))
            .orElseThrow();
        assertThat(lf112, instanceOf(LeafNode.class));

        final QName augmentChoice1 = QName.create(CONT_1, "augment-choice1");
        assertEquals(YangInstanceIdentifier.create(
            CONT_1_NODEID,
            AugmentationIdentifier.create(Set.of(augmentChoice1)),
            new NodeIdentifier(augmentChoice1),
            new NodeIdentifier(QName.create(CONT_1, "augment-choice2")),
            new NodeIdentifier(QName.create(CONT_1, "case11-choice-case-container"))),
            ((LeafNode<?>) lf112).body());
    }
}

@@ -1893,21 +1893,21 @@
 Reader(%22
-%7B%5Cn%22%0A
+%22%22%0A  
         
@@ -1912,16 +1912,24 @@
     
-  + %22  %5C
+%7B%0A              
 %22com
@@ -1946,16 +1946,12 @@
 ont1
-%5C
 %22: %7B
-%5Cn%22
 %0A   
@@ -1963,30 +1963,22 @@
     
-+ %22
+ 
    
- %5C
 %22lst11
-%5C
 %22: %5B
-%5Cn%22
 %0A   
@@ -1990,21 +1990,15 @@
     
-+ %22
       %7B
-%5Cn%22
 %0A   
@@ -2006,27 +2006,24 @@
         
-+ %22
         
 %5C%22key111
@@ -2018,31 +2018,24 @@
     
-%5C
 %22key111
-%5C
 %22: 
-%5C
 %22foo
-%5C
 %22,
-%5Cn%22
 %0A   
@@ -2047,41 +2047,31 @@
     
-+ %22
+ 
        
- %5C
 %22lf111
-%5C
 %22: 
-%5C
 %22bar
-%5C
 %22,
-%5Cn%22
 %0A   
@@ -2083,19 +2083,16 @@
     
-+ %22
         
 %5C%22lf
@@ -2091,20 +2091,17 @@
     
-%5C
 %22lf112
-%5C
 %22: 
-%5C
 %22/co
@@ -2148,12 +2148,8 @@
 iner
-%5C%22%5Cn
 %22%0A  
@@ -2162,21 +2162,15 @@
     
-+ %22
       %7D
-%5Cn%22
 %0A   
@@ -2182,19 +2182,13 @@
     
-+ %22
     %5D
-%5Cn%22
 %0A   
@@ -2200,17 +2200,11 @@
     
-+ %22  %7D%5Cn%22
+  %7D
 %0A   
@@ -2216,12 +2216,11 @@
     
-+ %22%7D
+%7D%22%22
 %22)))

Use a text block in YT1411Test