Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EntryEditorWidgetBot.java « bots « ui « integration « test « studio « directory « apache « org « java « main « src « test.integration.ui « tests - github.com/apache/directory-studio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15bfdecdb8c8ca2e93f3d8dc86250216c2c9cdf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *
 */
package org.apache.directory.studio.test.integration.ui.bots;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
import org.apache.directory.studio.test.integration.ui.utils.ContextMenuHelper;
import org.apache.directory.studio.test.integration.ui.utils.JobWatcher;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;


/**
 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
 */
class EntryEditorWidgetBot
{
    private SWTBot bot;

    EntryEditorWidgetBot( SWTBot bot )
    {
        this.bot = bot;
    }


    boolean isVisisble()
    {
        return bot.tree() != null;
    }


    List<String> getAttributeValues()
    {
        SWTBotTree tree = bot.tree();
        List<String> attributes = new ArrayList<String>();
        int rowCount = tree.rowCount();
        for ( int i = 0; i < rowCount; i++ )
        {
            String attribute = tree.cell( i, 0 );
            String value = tree.cell( i, 1 );
            attributes.add( attribute + ": " + value );
        }
        return attributes;
    }


    NewAttributeWizardBot openNewAttributeWizard()
    {
        ContextMenuHelper.clickContextMenu( bot.tree(), "New Attribute..." );
        return new NewAttributeWizardBot();
    }


    void typeValueAndFinish( String value, boolean wait )
    {
        SWTBotText text = bot.text( 1 );
        text.setText( value );

        if ( wait )
        {
            JobWatcher jobWatcher = new JobWatcher( BrowserCoreMessages.jobs__execute_ldif_name );
            bot.tree().pressShortcut( Keystrokes.LF );
            jobWatcher.waitUntilDone();
        }
        else
        {
            bot.tree().pressShortcut( Keystrokes.LF );
        }
    }


    public ErrorDialogBot typeValueAndFinishAndExpectErrorDialog( String value )
    {
        String shellText = BotUtils.shell( () -> typeValueAndFinish( value, false ), "Error" ).getText();
        return new ErrorDialogBot( shellText );
    }


    void cancelEditValue()
    {
        SWTBotTree tree = bot.tree( 0 );
        // TODO: Workaround for DIRAPI-228/DIRAPI-229
        //tree.getTreeItem( "objectClass" ).click();
        SWTBotTreeItem[] allItems = tree.getAllItems();
        for ( SWTBotTreeItem item : allItems )
        {
            if ( "objectclass".equalsIgnoreCase( item.getText() ) )
            {
                item.click();
                return;
            }
        }
    }


    void addValue( String attributeType )
    {
        SWTBotTree tree = bot.tree();
        tree.getTreeItem( attributeType ).click();
        ContextMenuHelper.clickContextMenu( bot.tree(), "New Value" );
    }


    EditAttributeWizardBot editAttribute( String attributeType, String value )
    {
        cancelEditValue();
        SWTBotTreeItem treeItem = getTreeItem( attributeType, value );
        treeItem.select();
        ContextMenuHelper.clickContextMenu( bot.tree(), "Edit Attribute Description" );
        return new EditAttributeWizardBot();
    }


    void editValue( String attributeType, String value )
    {
        cancelEditValue();
        SWTBotTreeItem treeItem = getTreeItem( attributeType, value );
        treeItem.doubleClick();
    }


    void editValueWith( String attributeType, String value, String valueEditorLabel )
    {
        cancelEditValue();
        SWTBotTreeItem treeItem = getTreeItem( attributeType, value );
        treeItem.select();
        ContextMenuHelper.clickContextMenu( bot.tree(), "Edit Value With", valueEditorLabel );
    }


    DnEditorDialogBot editValueExpectingDnEditor( String attributeType, String value )
    {
        editValue( attributeType, value );
        return new DnEditorDialogBot();
    }


    PasswordEditorDialogBot editValueExpectingPasswordEditor( String attributeType, String value )
    {
        editValue( attributeType, value );
        return new PasswordEditorDialogBot();
    }


    AciItemEditorDialogBot editValueExpectingAciItemEditor( String attributeType, String value )
    {
        editValue( attributeType, value );
        return new AciItemEditorDialogBot();
    }


    SubtreeSpecificationEditorDialogBot editValueExpectingSubtreeSpecificationEditor( String attributeType,
        String value )
    {
        editValue( attributeType, value );
        return new SubtreeSpecificationEditorDialogBot();
    }


    CertificateEditorDialogBot editValueExpectingCertificateEditor( String attributeType, String value )
    {
        editValue( attributeType, value );
        return new CertificateEditorDialogBot();
    }


    HexEditorDialogBot editValueExpectingHexEditor( String attributeType, String value )
    {
        editValue( attributeType, value );
        return new HexEditorDialogBot();
    }


    TextEditorDialogBot editValueWithTextEditor( String attributeType, String value )
    {
        editValueWith( attributeType, value, "^Text Editor$" );
        return new TextEditorDialogBot();
    }


    private SWTBotTreeItem getTreeItem( String attributeType, String value )
    {
        SWTBotTree tree = bot.tree();
        SWTBotTreeItem[] allItems = tree.getAllItems();
        for ( SWTBotTreeItem item : allItems )
        {
            if ( item.cell( 0 ).equalsIgnoreCase( attributeType )
                && ( value == null || item.cell( 1 ).equals( value ) ) )
            {
                return item;
            }
        }
        throw new WidgetNotFoundException( "Attribute " + attributeType + ":" + value + " not found." );
    }


    private List<SWTBotTreeItem> getTreeItems( String... attributeTypes )
    {
        List<String> attributeTypeList = Arrays.asList( attributeTypes );
        List<SWTBotTreeItem> items = new ArrayList<>();
        SWTBotTree tree = bot.tree();
        SWTBotTreeItem[] allItems = tree.getAllItems();
        for ( SWTBotTreeItem item : allItems )
        {
            if ( attributeTypeList.contains( item.cell( 0 ) ) )
            {
                items.add( item );
            }
        }
        return items;
    }


    void deleteValue( String attributeType, String value )
    {
        SWTBotTreeItem treeItem = getTreeItem( attributeType, value );
        treeItem.select();
        ContextMenuHelper.clickContextMenu( bot.tree(), "Delete Value" );
        DeleteDialogBot deleteDialogBot = new DeleteDialogBot( DeleteDialogBot.DELETE_VALUE_TITLE );
        deleteDialogBot.clickOkButton();
    }


    public ErrorDialogBot deleteValueExpectingErrorDialog( String attributeType, String value )
    {
        SWTBotTreeItem treeItem = getTreeItem( attributeType, value );
        treeItem.select();
        ContextMenuHelper.clickContextMenu( bot.tree(), "Delete Value" );
        DeleteDialogBot deleteDialogBot = new DeleteDialogBot( DeleteDialogBot.DELETE_VALUE_TITLE );
        return deleteDialogBot.clickOkButtonExpectingErrorDialog();
    }


    public void copyValue( String attributeType, String value )
    {

        SWTBotTreeItem treeItem = getTreeItem( attributeType, value );
        treeItem.select();
        ContextMenuHelper.clickContextMenu( bot.tree(), "Copy Value" );
    }


    public void copyValues( String... attributeTypes )
    {
        List<SWTBotTreeItem> items = getTreeItems( attributeTypes );
        bot.tree().select( items.toArray( new SWTBotTreeItem[0] ) );
        ContextMenuHelper.clickContextMenu( bot.tree(), "Copy Values" );
    }


    public void pasteValue()
    {
        ContextMenuHelper.clickContextMenu( bot.tree(), "Paste Value" );
    }


    public void pasteValues()
    {
        ContextMenuHelper.clickContextMenu( bot.tree(), "Paste Values" );
    }

}