1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package test.rowset.serial;
  24 
  25 import java.net.URL;
  26 import javax.sql.rowset.serial.SerialDatalink;
  27 import javax.sql.rowset.serial.SerialException;
  28 import static org.testng.Assert.*;
  29 import org.testng.annotations.BeforeMethod;
  30 import org.testng.annotations.Test;
  31 import util.BaseTest;
  32 
  33 public class SerialDataLinkTests extends BaseTest {
  34 
  35     private URL u;
  36     private URL u1;
  37     private SerialDatalink dl;
  38 
  39     @BeforeMethod
  40     public void setUpMethod() throws Exception {
  41         u = new URL("http://www.oracle.com/");
  42         u1 = new URL("http://www.usatoday.com/");
  43         dl = new SerialDatalink(u);
  44     }
  45 
  46     /*
  47      * Validate that a SerialException is thrown if the URL is null
  48      */
  49     @Test(expectedExceptions = SerialException.class)
  50     public void test() throws Exception {
  51         SerialDatalink dl1 = new SerialDatalink(null);
  52     }
  53 
  54     /*
  55      * Validate that getDatalink() returns the same URL used to create the
  56      * SerialDatalink object
  57      */
  58     @Test
  59     public void test01() throws Exception {
  60         URL u2 = dl.getDatalink();
  61         assertTrue(u2.equals(u));
  62         assertTrue(u2.sameFile(u));
  63     }
  64 
  65     /*
  66      * Validate that URL returned from getDatalink() differs from a URL that was
  67      * not used to create the SerialDatalink
  68      */
  69     @Test
  70     public void test02() throws Exception {
  71         URL u2 = dl.getDatalink();
  72         assertFalse(u2.equals(u1));
  73         assertFalse(u2.sameFile(u1));
  74     }
  75 
  76     /*
  77      * Create a clone of a SerialDatalink and validate that it is equal to the
  78      * SerialDatalink it was cloned from
  79      */
  80     @Test
  81     public void test03() throws Exception {
  82         SerialDatalink dl2 = (SerialDatalink) dl.clone();
  83         assertTrue(dl.equals(dl2));
  84         SerialDatalink dl3 = new SerialDatalink(u1);
  85         assertFalse(dl2.equals(dl3));
  86     }
  87 
  88     /*
  89      * Validate that a SerialDatalink that is serialized & deserialized is
  90      * equal to itself
  91      */
  92     @Test
  93     public void test04() throws Exception {
  94         SerialDatalink dl2 = serializeDeserializeObject(dl);
  95         SerialDatalink dl3 = new SerialDatalink(u);
  96         assertTrue(dl.equals(dl2));
  97         assertTrue(dl3.equals(dl2));
  98     }
  99 
 100     /**
 101      * Validate that a SerialDatalink that is serialized & deserialized is not equal
 102      * to to a SerialDatalink created using a different URL
 103      */
 104     @Test
 105     public void test05() throws Exception {
 106         SerialDatalink dl2 = serializeDeserializeObject(dl);
 107         SerialDatalink d3 = new SerialDatalink(u1);
 108         assertFalse(d3.equals(dl2));
 109     }
 110 }