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  package org.apache.myfaces.view.facelets.tag.composite;
20  
21  import java.beans.BeanDescriptor;
22  import java.io.ByteArrayInputStream;
23  import java.io.ByteArrayOutputStream;
24  import java.io.ObjectInputStream;
25  import java.io.ObjectOutputStream;
26  
27  import javax.faces.component.UINamingContainer;
28  
29  import junit.framework.TestCase;
30  
31  public class SerializableAttributesTestCase extends TestCase
32  {
33  
34      @Override
35      protected void setUp() throws Exception
36      {
37          super.setUp();
38      }
39  
40      @Override
41      protected void tearDown() throws Exception
42      {
43          super.tearDown();
44      }
45      
46      public void testSerializeCompositeResourceWrapper() throws Exception
47      {
48          CompositeResouceWrapper subject = new CompositeResouceWrapper();
49          subject.setResourceName("testRes");
50          subject.setLibraryName("testLib");
51          subject.setContentType(null);
52          
53          ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
54          ObjectOutputStream oos = new ObjectOutputStream(baos);
55          oos.writeObject(subject);
56          oos.flush();
57          baos.flush();
58          ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
59          ObjectInputStream ois = new ObjectInputStream(bais);
60          CompositeResouceWrapper blorg = (CompositeResouceWrapper) ois.readObject();
61          assertEquals(blorg.getResourceName(), subject.getResourceName());
62          assertEquals(blorg.getLibraryName(), subject.getLibraryName());
63          assertEquals(blorg.getContentType(), subject.getContentType());
64          oos.close();
65          ois.close();
66      }
67      
68      public void testSerializeCompositeComponentBeanInfo() throws Exception
69      {
70          BeanDescriptor descriptor = new BeanDescriptor(UINamingContainer.class);
71          CompositeComponentBeanInfo subject = new CompositeComponentBeanInfo(descriptor);
72          CompositeComponentPropertyDescriptor pd = new CompositeComponentPropertyDescriptor("attrName");
73          pd.setValue("type","someClass");
74          subject.getPropertyDescriptorsList().add(pd);       
75          ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
76          ObjectOutputStream oos = new ObjectOutputStream(baos);
77          oos.writeObject(subject);
78          oos.flush();
79          baos.flush();
80          ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
81          ObjectInputStream ois = new ObjectInputStream(bais);
82          CompositeComponentBeanInfo blorg = (CompositeComponentBeanInfo) ois.readObject();
83          
84          assertEquals(UINamingContainer.class, blorg.getBeanDescriptor().getBeanClass());
85          assertEquals(pd.getName(), blorg.getPropertyDescriptorsList().get(0).getName());
86          oos.close();
87          ois.close();
88      }
89  }