alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

/*
 * Synchronization1.java.java
 *
 */

package org.netbeans.test.java.synchronization.Synchronization1;

import java.awt.EventQueue;
import org.netbeans.junit.NbTest;
import org.netbeans.junit.NbTestSuite;
import java.awt.event.ActionEvent;
import org.openide.loaders.DataObject;
import junit.textui.TestRunner;
import java.io.PrintWriter;
import org.openide.nodes.Node;
import org.netbeans.test.java.XRunner;
import org.netbeans.modules.java.JavaDataObject;
import org.netbeans.modules.java.ui.actions.SynchronizeAction;
import org.openide.src.ClassElement;
import org.openide.src.SourceElement;
import org.openide.src.Identifier;
import org.openide.util.SharedClassObject;
import org.netbeans.modules.java.settings.JavaSynchronizationSettings;

/** Java Module General API Test: Synchronization 1
 * 

What it tests:
* Synchronization between interfaces and implementations. * This test creates a class, which implements existing interfaces. * Synchronization 1 is intent on implementing 2 interfaces. * Test is focused on checking of correctness of generated code. *

How it works:
* New class is created using DataObject.createFromTemplate() and ClassElement.setInterfaces() is called. * And then SynchronizeAction is actionPerformed(). * These actions cause generating of .java code. This code is compared with supposed one. *

Output:
* Generated Java code. *

Possible reasons of failure:
*

Some methods are not properly added or added with bad parameters, modifiers...
* See .diff file to get which ones *

Bad indentation
* This is probably not a bug of Java Module. (Editor Bug) * In .diff file could be some whitespaces. *

Exception occured:
* See .out file for StackTrace * * @author Jan Becicka */ public class Synchronization1 extends XRunner { private final int DELAY = 4000; public static void main(java.lang.String[] args) { TestRunner.run(suite()); } public Synchronization1() { super(""); } public Synchronization1(java.lang.String testName) { super(testName); } public static NbTest suite() { return new NbTestSuite(Synchronization1.class); } /** "body" of this TestCase * @param o SourceElement - target for generating * @param log log is used for logging StackTraces * @throws Exception * @return true if test passed * false if failed */ public boolean go(Object o, PrintWriter log) throws Exception { final ClassElement clazz = ((SourceElement) o).getClasses()[0]; boolean passed = true; JavaDataObject JDO = (JavaDataObject) clazz.getSource().getCookie(JavaDataObject.class); JDO.setSynchronizationType(JavaDataObject.CONNECT_NOT); clazz.setInterfaces(new Identifier[] {Identifier.create(packageName + ".ifaces.RootInterface"), Identifier.create( packageName + ".ifaces.OtherInterface")}); Thread.currentThread().sleep(DELAY); JDO.setSynchronizationType(JavaDataObject.CONNECT_AUTO); EventQueue.invokeAndWait(new Runnable() { public void run() { Node node = (((DataObject) clazz.getSource().getCookie(DataObject.class)).getNodeDelegate()); SynchronizeAction sa = (SynchronizeAction) SharedClassObject.findObject(SynchronizeAction.class); ActionEvent ae = new ActionEvent(node,0,""); sa.actionPerformed(ae); } }); clazz.getSource().prepare().waitFinished(); //Strange, but I don't know better way Thread.currentThread().sleep(DELAY); return passed; } /** */ protected void setUp() { super.setUp(); name = "JavaTestSourceSynchronization1"; packageName = "org.netbeans.test.java.testsources"; JavaSynchronizationSettings jss = (JavaSynchronizationSettings) JavaSynchronizationSettings.findObject(JavaSynchronizationSettings.class, true); jss.setEnabled(true); } protected void tearDown(){ super.tearDown(); JavaSynchronizationSettings jss = (JavaSynchronizationSettings) JavaSynchronizationSettings.findObject(JavaSynchronizationSettings.class, true); jss.setEnabled(false); } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.