@Test
  public void testStorageDependsOnInstance() throws Exception {
    StorageUtil.dropAllConnections();

    ViewContext context1 = createNiceMock(ViewContext.class);
    ViewContext context2 = createNiceMock(ViewContext.class);
    ViewContext context3 = createNiceMock(ViewContext.class);
    expect(context1.getProperties()).andReturn(properties).anyTimes();
    expect(context1.getUsername()).andReturn("ambari-qa").anyTimes();
    expect(context1.getInstanceName()).andReturn("Pig1").anyTimes();

    expect(context2.getProperties()).andReturn(properties).anyTimes();
    expect(context2.getUsername()).andReturn("ambari-qa").anyTimes();
    expect(context2.getInstanceName()).andReturn("Pig2").anyTimes();

    expect(context3.getProperties()).andReturn(properties).anyTimes();
    expect(context3.getUsername()).andReturn("ambari-qa").anyTimes();
    expect(context3.getInstanceName()).andReturn("Pig1").anyTimes();

    replay(context1, context2, context3);

    Storage storage1 = StorageUtil.getInstance(context1).getStorage();
    Storage storage2 = StorageUtil.getInstance(context2).getStorage();
    Assert.assertNotSame(storage1, storage2);

    Storage storage1_2 = StorageUtil.getInstance(context1).getStorage();
    Storage storage2_2 = StorageUtil.getInstance(context1).getStorage();
    Assert.assertSame(storage1_2, storage2_2);

    Storage storage1_3 = StorageUtil.getInstance(context1).getStorage();
    Storage storage3_3 = StorageUtil.getInstance(context3).getStorage();
    Assert.assertSame(storage1_3, storage3_3);
  }
Test cases that verify all services altogether
contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/IntegrationalTest.java