View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.renderkit;
21  
22  import org.apache.myfaces.tobago.internal.util.JsonUtils;
23  import org.junit.jupiter.api.Assertions;
24  import org.junit.jupiter.api.Test;
25  
26  public class CommandUnitTest {
27  
28    @Test
29    public void test() {
30  
31      final Command a = new Command();
32      a.setAction("a action");
33      a.setCollapse(new Collapse(Collapse.Action.show, "a collapse"));
34      a.setConfirmation("a conf");
35      a.setExecute("a execute");
36  
37      final Command b = new Command();
38      b.setAction("b action");
39      b.setCollapse(new Collapse(Collapse.Action.show, "b collapse"));
40      b.setConfirmation("b conf");
41      b.setExecute("b execute");
42  
43      a.merge(b);
44  
45      Assertions.assertEquals(
46          ("{'click':"
47              + "{'action':'a action',"
48              + "'execute':'a execute b execute'"
49              + ",'collapse':{'transition':'show','forId':'a collapse'}"
50              + ",'confirmation':'a conf'}}")
51              .replaceAll("'", "\""),
52          JsonUtils.encode(new CommandMap(a)));
53  
54      final Command c = new Command();
55  
56      c.merge(b);
57  
58      Assertions.assertEquals(
59          ("{'click':"
60              + "{'action':'b action',"
61              + "'execute':'b execute',"
62              + "'collapse':{'transition':'show','forId':'b collapse'},"
63              + "'confirmation':'b conf'}}")
64              .replaceAll("'", "\""),
65          JsonUtils.encode(new CommandMap(c)));
66  
67    }
68  }